Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline tracking in promotions #11

Merged
merged 2 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/pipelines/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (p *Pipeline) EvaluateChangeIns(yamlPath string) error {
continue
}

fun, err := when.NewChangeInFunctionFromWhenInputList(input, yamlPath)
fun, err := when.NewChangeInFunctionFromWhenInputList(&w, input, yamlPath)
if err != nil {
panic(err)
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/when/changein.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ChangeInFunction struct {
diffList []string
}

func NewChangeInFunctionFromWhenInputList(input *gabs.Container, yamlPath string) (*ChangeInFunction, error) {
func NewChangeInFunctionFromWhenInputList(when *WhenExpression, input *gabs.Container, yamlPath string) (*ChangeInFunction, error) {
params := ChangeInFunctionParams{
PathPatterns: []string{},
ExcludedPathPatterns: []string{},
Expand Down Expand Up @@ -68,6 +68,12 @@ func NewChangeInFunctionFromWhenInputList(input *gabs.Container, yamlPath string
default:
return nil, fmt.Errorf("Unknown value type pipeline_file in change_in expression.")
}
} else {
if when.Path[0] == "promotions" {
params.TrackPipelineFile = false
} else {
params.TrackPipelineFile = true
}
}

if input.Exists("params", "1", "on_tags") {
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/change_in_pipeline_file_tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
require_relative "../e2e"
require 'yaml'

#
# By default, when a Pipeline YAML file is changed, every block is executed.
# The reasoning is that if you have changed the YAML file, conditions have
# changed and it is better to execute every block.
#
# The value of the pipeline_file is by default 'track' for blocks, queues,
# auto_cancel, and fast_fail.
#
# However, for promotions, the default value is 'ignore'.
#

#
# Prepare a repository with two branches, master and dev.
#
Expand Down Expand Up @@ -52,6 +63,19 @@
- name: Hello
commands:
- echo "Hello World"

promotions:
- name: P1
auto_promote:
when: "change_in('/lib')"

- name: P2
auto_promote:
when: "change_in('/lib', {pipeline_file: 'ignore'})"

- name: P3
auto_promote:
when: "change_in('/lib', {pipeline_file: 'track'})"
})

system %{
Expand Down Expand Up @@ -117,4 +141,17 @@
- name: Hello
commands:
- echo "Hello World"

promotions:
- name: P1
auto_promote:
when: "false"

- name: P2
auto_promote:
when: "false"

- name: P3
auto_promote:
when: "true"
}))