Skip to content

Commit 1184481

Browse files
authored
fix(jenkins): use WORKSPACE instead of AGENT_WORKDIR (#1348)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 0816d96 commit 1184481

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

pkg/attestation/crafter/crafter_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,12 @@ func (s *crafterSuite) TestResolveEnvVars() {
280280
},
281281
expectedEnvVars: map[string]string{
282282
// Missing var: GIT_BRANCH
283-
"CUSTOM_VAR_1": "custom_value_1",
284-
"CUSTOM_VAR_2": "custom_value_2",
285-
"JOB_NAME": "some-job",
286-
"BUILD_URL": "http://some-url",
287-
"AGENT_WORKDIR": "/some/home/dir",
288-
"NODE_NAME": "some-node",
283+
"CUSTOM_VAR_1": "custom_value_1",
284+
"CUSTOM_VAR_2": "custom_value_2",
285+
"JOB_NAME": "some-job",
286+
"BUILD_URL": "http://some-url",
287+
"WORKSPACE": "/some/home/dir",
288+
"NODE_NAME": "some-node",
289289
},
290290
}, {
291291
name: "all optional jenkins variable with no error",
@@ -298,14 +298,14 @@ func (s *crafterSuite) TestResolveEnvVars() {
298298
"CUSTOM_VAR_2": "custom_value_2",
299299
},
300300
expectedEnvVars: map[string]string{
301-
"GIT_BRANCH": "some-branch", // optional var 1
302-
"GIT_COMMIT": "some-commit", // optional var 2
303-
"CUSTOM_VAR_1": "custom_value_1",
304-
"CUSTOM_VAR_2": "custom_value_2",
305-
"JOB_NAME": "some-job",
306-
"BUILD_URL": "http://some-url",
307-
"AGENT_WORKDIR": "/some/home/dir",
308-
"NODE_NAME": "some-node",
301+
"GIT_BRANCH": "some-branch", // optional var 1
302+
"GIT_COMMIT": "some-commit", // optional var 2
303+
"CUSTOM_VAR_1": "custom_value_1",
304+
"CUSTOM_VAR_2": "custom_value_2",
305+
"JOB_NAME": "some-job",
306+
"BUILD_URL": "http://some-url",
307+
"WORKSPACE": "/some/home/dir",
308+
"NODE_NAME": "some-node",
309309
},
310310
},
311311
}
@@ -324,7 +324,7 @@ func (s *crafterSuite) TestResolveEnvVars() {
324324
contract = "testdata/contracts/jenkins_with_env_vars.yaml"
325325
s.T().Setenv("JOB_NAME", "some-job")
326326
s.T().Setenv("BUILD_URL", "http://some-url")
327-
s.T().Setenv("AGENT_WORKDIR", "/some/home/dir")
327+
s.T().Setenv("WORKSPACE", "/some/home/dir")
328328
s.T().Setenv("NODE_NAME", "some-node")
329329
s.T().Setenv("JENKINS_HOME", "/some/home/dir")
330330
runner = runners.NewJenkinsJob()

pkg/attestation/crafter/runners/jenkinsjob.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -55,7 +55,10 @@ func (r *JenkinsJob) ListEnvVars() []*EnvVarDefinition {
5555
{"GIT_COMMIT", true},
5656

5757
// Some info about the agent
58-
{"AGENT_WORKDIR", false},
58+
// We've found this one to be optional
59+
{"AGENT_WORKDIR", true},
60+
// Workspace is required as long as the jobs run inside a `node` block
61+
{"WORKSPACE", false},
5962
{"NODE_NAME", false},
6063
}
6164
}

pkg/attestation/crafter/runners/jenkinsjob_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -82,7 +82,8 @@ func (s *jenkinsJobSuite) TestListEnvVars() {
8282
{"BUILD_URL", false},
8383
{"GIT_BRANCH", true},
8484
{"GIT_COMMIT", true},
85-
{"AGENT_WORKDIR", false},
85+
{"AGENT_WORKDIR", true},
86+
{"WORKSPACE", false},
8687
{"NODE_NAME", false},
8788
}, s.runner.ListEnvVars())
8889
}
@@ -98,7 +99,7 @@ func (s *jenkinsJobSuite) TestResolveEnvVars() {
9899
os.Unsetenv("GIT_COMMIT")
99100
resolvedEnvVars, errors = s.runner.ResolveEnvVars()
100101
s.Empty(errors)
101-
s.Equal(reuiredJenkinsJobTestingEnvVars, resolvedEnvVars)
102+
s.Equal(requiredJenkinsJobTestingEnvVars, resolvedEnvVars)
102103
}
103104

104105
func (s *jenkinsJobSuite) TestRunURI() {
@@ -119,19 +120,19 @@ func (s *jenkinsJobSuite) SetupTest() {
119120
}
120121

121122
var jenkinsJobTestingEnvVars = map[string]string{
122-
"JOB_NAME": "some-jenkins-job",
123-
"BUILD_URL": "http://some-build-url/",
124-
"AGENT_WORKDIR": "/home/sample/agent",
125-
"NODE_NAME": "some-node",
126-
"GIT_BRANCH": "somebranch",
127-
"GIT_COMMIT": "somecommit",
123+
"JOB_NAME": "some-jenkins-job",
124+
"BUILD_URL": "http://some-build-url/",
125+
"WORKSPACE": "/home/sample/agent",
126+
"NODE_NAME": "some-node",
127+
"GIT_BRANCH": "somebranch",
128+
"GIT_COMMIT": "somecommit",
128129
}
129130

130-
var reuiredJenkinsJobTestingEnvVars = map[string]string{
131-
"JOB_NAME": "some-jenkins-job",
132-
"BUILD_URL": "http://some-build-url/",
133-
"AGENT_WORKDIR": "/home/sample/agent",
134-
"NODE_NAME": "some-node",
131+
var requiredJenkinsJobTestingEnvVars = map[string]string{
132+
"JOB_NAME": "some-jenkins-job",
133+
"BUILD_URL": "http://some-build-url/",
134+
"WORKSPACE": "/home/sample/agent",
135+
"NODE_NAME": "some-node",
135136
}
136137

137138
// Run the tests

0 commit comments

Comments
 (0)