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

fix: instantiated pipeline vars #149

Closed
Closed
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
15 changes: 14 additions & 1 deletion cogito/putter.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,20 @@ func concourseBuildURL(env Environment) string {
// BUILD_PIPELINE_INSTANCE_VARS: {"branch":"stable"}
// https://ci.example.com/teams/main/pipelines/cogito/jobs/autocat/builds/3?vars=%7B%22branch%22%3A%22stable%22%7D
if env.BuildPipelineInstanceVars != "" {
buildURL += fmt.Sprintf("?vars=%s", url.QueryEscape(env.BuildPipelineInstanceVars))
//convert the JSON instance vars into URL parameters
var instanceVars map[string]interface{}
if err := json.Unmarshal([]byte(env.BuildPipelineInstanceVars), &instanceVars); err != nil {
panic(err)
}
params := url.Values{}
for key, value := range instanceVars {
valueStr := fmt.Sprintf("\"%v\"", value)
params.Add("vars."+key, valueStr)
}
encodedString := params.Encode()
//concourse wants spaces not + if you have them in a variable
paramsString := strings.ReplaceAll(encodedString, "+", " ")
buildURL += fmt.Sprintf("?%s", paramsString)
}

return buildURL
Expand Down
10 changes: 8 additions & 2 deletions cogito/putter_private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,19 @@ func TestConcourseBuildURL(t *testing.T) {
name: "instanced vars 1",
env: testhelp.MergeStructs(baseEnv,
Environment{BuildPipelineInstanceVars: `{"branch":"stable"}`}),
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars=%7B%22branch%22%3A%22stable%22%7D",
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars.branch=%22stable%22",
Copy link
Contributor

@aliculPix4D aliculPix4D Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marco-m-pix4d should we start using go-vcr pkg in these tests?

I wonder if we could have catch'ed this sooner if we used it already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we start using go-vcr pkg in these tests?

Probably.

I wonder if we could have catch'ed this sooner if we used it already.

This is the part I don't understand. I think that I tested against https://github.com/marco-m/concourse-in-a-box, so I don't understand why this now fails. True in any case that if we had a go-vcr trace, we could answer this question...

},
{
name: "instanced vars 2",
env: testhelp.MergeStructs(baseEnv,
Environment{BuildPipelineInstanceVars: `{"branch":"stable","foo":"bar"}`}),
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars=%7B%22branch%22%3A%22stable%22%2C%22foo%22%3A%22bar%22%7D",
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars.branch=%22stable%22&vars.foo=%22bar%22",
},
{
name: "instanced vars 3",
env: testhelp.MergeStructs(baseEnv,
Environment{BuildPipelineInstanceVars: `{"branch":"stable", "variable":"has spaces in it"}`}),
want: "https://ci.example.com/teams/devs/pipelines/magritte/jobs/paint/builds/42?vars.branch=%22stable%22&vars.variable=%22has spaces in it%22",
},
}

Expand Down