Skip to content

Commit c228913

Browse files
Nguyen, TungNguyen, Tung
Nguyen, Tung
authored and
Nguyen, Tung
committed
Add trigger options
Include pipeline caching behaviors and notification setting
1 parent 4df8740 commit c228913

File tree

4 files changed

+106
-6
lines changed

4 files changed

+106
-6
lines changed

client/pipeline.go

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Trigger struct {
4848
ModifiedFilesGlob string `json:"modifiedFilesGlob,omitempty"`
4949
Provider string `json:"provider,omitempty"`
5050
Disabled bool `json:"disabled,omitempty"`
51+
Options *TriggerOptions `json:"options,omitempty"`
5152
PullRequestAllowForkEvents bool `json:"pullRequestAllowForkEvents,omitempty"`
5253
CommitStatusTitle string `json:"commitStatusTitle,omitempty"`
5354
Context string `json:"context,omitempty"`
@@ -56,6 +57,13 @@ type Trigger struct {
5657
Variables []Variable `json:"variables,omitempty"`
5758
}
5859

60+
type TriggerOptions struct {
61+
NoCache string `json:"noCache,omitempty"`
62+
NoCfCache string `json:"noCfCache,omitempty"`
63+
ResetVolume string `json:"resetVolume,omitempty"`
64+
EnableNotifications string `json:"enableNotifications,omitempty"`
65+
}
66+
5967
type RuntimeEnvironment struct {
6068
Name string `json:"name,omitempty"`
6169
Memory string `json:"memory,omitempty"`

codefresh/resource_pipeline.go

+51
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,34 @@ func resourcePipeline() *schema.Resource {
183183
Optional: true,
184184
Default: false,
185185
},
186+
"options": {
187+
Type: schema.TypeList,
188+
Optional: true,
189+
Elem: &schema.Resource{
190+
Schema: map[string]*schema.Schema{
191+
"no_cache": {
192+
Type: schema.TypeBool,
193+
Optional: true,
194+
Default: false,
195+
},
196+
"no_cf_cache": {
197+
Type: schema.TypeBool,
198+
Optional: true,
199+
Default: false,
200+
},
201+
"reset_volume": {
202+
Type: schema.TypeBool,
203+
Optional: true,
204+
Default: false,
205+
},
206+
"enable_notifications": {
207+
Type: schema.TypeBool,
208+
Optional: true,
209+
Default: false,
210+
},
211+
},
212+
},
213+
},
186214
"pull_request_allow_fork_events": {
187215
Type: schema.TypeBool,
188216
Optional: true,
@@ -541,6 +569,17 @@ func flattenSpecRuntimeEnvironment(spec cfClient.RuntimeEnvironment) []map[strin
541569
}
542570
}
543571

572+
func flattenTriggerOptions(options cfClient.TriggerOptions) []map[string]interface{} {
573+
return []map[string]interface{}{
574+
{
575+
"no_cache": options.NoCache,
576+
"no_cf_cache": options.NoCfCache,
577+
"reset_volume": options.ResetVolume,
578+
"enable_notifications": options.EnableNotifications,
579+
},
580+
}
581+
}
582+
544583
func flattenTriggers(triggers []cfClient.Trigger) []map[string]interface{} {
545584
var res = make([]map[string]interface{}, len(triggers))
546585
for i, trigger := range triggers {
@@ -556,6 +595,9 @@ func flattenTriggers(triggers []cfClient.Trigger) []map[string]interface{} {
556595
m["comment_regex"] = trigger.CommentRegex
557596
m["modified_files_glob"] = trigger.ModifiedFilesGlob
558597
m["disabled"] = trigger.Disabled
598+
if trigger.Options != nil {
599+
m["options"] = flattenTriggerOptions(*trigger.Options)
600+
}
559601
m["pull_request_allow_fork_events"] = trigger.PullRequestAllowForkEvents
560602
m["commit_status_title"] = trigger.CommitStatusTitle
561603
m["provider"] = trigger.Provider
@@ -649,6 +691,15 @@ func mapResourceToPipeline(d *schema.ResourceData) *cfClient.Pipeline {
649691
}
650692
variables := d.Get(fmt.Sprintf("spec.0.trigger.%v.variables", idx)).(map[string]interface{})
651693
codefreshTrigger.SetVariables(variables)
694+
if _, ok := d.GetOk(fmt.Sprintf("spec.0.trigger.%v.options", idx)); ok {
695+
options := cfClient.TriggerOptions{
696+
NoCache: d.Get(fmt.Sprintf("spec.0.trigger.%v.options.0.no_cache", idx)).(string),
697+
NoCfCache: d.Get(fmt.Sprintf("spec.0.trigger.%v.options.0.no_cf_cache", idx)).(string),
698+
ResetVolume: d.Get(fmt.Sprintf("spec.0.trigger.%v.options.0.reset_volume", idx)).(string),
699+
EnableNotifications: d.Get(fmt.Sprintf("spec.0.trigger.%v.options.0.enable_notifications", idx)).(string),
700+
}
701+
codefreshTrigger.Options = &options
702+
}
652703
if _, ok := d.GetOk(fmt.Sprintf("spec.0.trigger.%v.runtime_environment", idx)); ok {
653704
triggerRuntime := cfClient.RuntimeEnvironment{
654705
Name: d.Get(fmt.Sprintf("spec.0.trigger.%v.runtime_environment.0.name", idx)).(string),

codefresh/resource_pipeline_test.go

+37-6
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ func TestAccCodefreshPipeline_Triggers(t *testing.T) {
268268
"tags",
269269
"git",
270270
"shared_context2",
271+
true,
272+
true,
273+
true,
274+
true,
271275
"push.tags",
272276
"codefresh-contrib/react-sample-app",
273277
"triggerTestVar",
@@ -284,6 +288,10 @@ func TestAccCodefreshPipeline_Triggers(t *testing.T) {
284288
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.0.name", "commits"),
285289
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.name", "tags"),
286290
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.contexts.0", "shared_context2"),
291+
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.options.0.no_cache", "true"),
292+
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.options.0.no_cf_cache", "true"),
293+
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.options.0.reset_volume", "true"),
294+
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.options.0.enable_notifications", "true"),
287295
),
288296
},
289297
{
@@ -310,6 +318,10 @@ func TestAccCodefreshPipeline_Triggers(t *testing.T) {
310318
"tags",
311319
"git",
312320
"shared_context2_update",
321+
true,
322+
true,
323+
false,
324+
false,
313325
"push.tags",
314326
"codefresh-contrib/react-sample-app",
315327
"triggerTestVar",
@@ -324,6 +336,10 @@ func TestAccCodefreshPipeline_Triggers(t *testing.T) {
324336
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.0.comment_regex", "/PR comment2/gi"),
325337
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.variables.triggerTestVar", "triggerTestValue"),
326338
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.contexts.0", "shared_context2_update"),
339+
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.options.0.no_cache", "true"),
340+
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.options.0.no_cf_cache", "true"),
341+
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.options.0.reset_volume", "false"),
342+
resource.TestCheckResourceAttr(resourceName, "spec.0.trigger.1.options.0.enable_notifications", "false"),
327343
),
328344
},
329345
},
@@ -703,12 +719,17 @@ func testAccCodefreshPipelineBasicConfigTriggers(
703719
trigger1Repo,
704720
trigger2Name,
705721
trigger2Context,
706-
trigger2Contexts,
722+
trigger2Contexts string,
723+
trigger2NoCache,
724+
trigger2NoCfCache,
725+
trigger2ResetVolume,
726+
trigger2EnableNotifications bool,
707727
trigger2Event,
708728
trigger2Repo,
709729
trigger2VarName,
710730
trigger2VarValue,
711-
trigger2CommitStatusTitle string) string {
731+
trigger2CommitStatusTitle string,
732+
) string {
712733
return fmt.Sprintf(`
713734
resource "codefresh_pipeline" "test" {
714735
@@ -753,12 +774,18 @@ resource "codefresh_pipeline" "test" {
753774
trigger {
754775
name = %q
755776
branch_regex = "/.*/gi"
756-
context = %q
757-
contexts = [
758-
%q
759-
]
777+
context = %q
778+
contexts = [
779+
%q
780+
]
760781
description = ""
761782
disabled = false
783+
options = {
784+
no_cache = %t
785+
no_cf_cache = %t
786+
reset_volume = %t
787+
enable_notifications = %t
788+
}
762789
events = [
763790
%q
764791
]
@@ -794,6 +821,10 @@ resource "codefresh_pipeline" "test" {
794821
trigger2Name,
795822
trigger2Context,
796823
trigger2Contexts,
824+
trigger2NoCache,
825+
trigger2NoCfCache,
826+
trigger2ResetVolume,
827+
trigger2EnableNotifications,
797828
trigger2Event,
798829
trigger2Repo,
799830
trigger2VarName,

docs/resources/pipeline.md

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ resource "codefresh_pipeline" "test" {
142142
- `pull_request_allow_fork_events` - (Optional) Boolean. If this trigger is also applicable to Git forks.
143143
- `contexts` - (Optional) A list of strings representing the contexts ([shared_configuration](https://codefresh.io/docs/docs/configure-ci-cd-pipeline/shared-configuration/)) to be loaded when the trigger is executed
144144
- `runtime_environment` - (Optional) A collection of `runtime_environment` blocks as documented below.
145+
- `options`: (Optional) A collection `option` blocks as documented below.
145146
---
146147

147148
`runtime_environment` supports the following:
@@ -153,6 +154,15 @@ resource "codefresh_pipeline" "test" {
153154

154155
---
155156

157+
`options` supports the following:
158+
159+
- `no_cache` - (Required) Boolean. If true, docker layer cache is disabled. Default false
160+
- `no_cf_cache` - (Optional) Boolean. If true, extra Codefresh caching is disabled. Default false
161+
- `reset_volume` - (Optional) Boolean. If true, all files on volume will be deleted before each execution. Default false
162+
- `enable_notifications` - (Optional) Boolean. If false the pipeline will not send notifications to Slack and status updates back to the Git provider. Default false
163+
164+
---
165+
156166
`termination_policy` supports the following:
157167

158168
- `on_create_branch` - (Optional) A `on_create_branch` block as documented below.

0 commit comments

Comments
 (0)