From 11c91bd8d73a6ec2888c532ee3bde039109ea169 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Tue, 24 Sep 2024 14:29:44 +0200 Subject: [PATCH] fix(jenkins): use WORKSPACE instead of AGENT_WORKDIR Signed-off-by: Miguel Martinez --- pkg/attestation/crafter/runners/jenkinsjob.go | 7 +++-- .../crafter/runners/jenkinsjob_test.go | 29 ++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pkg/attestation/crafter/runners/jenkinsjob.go b/pkg/attestation/crafter/runners/jenkinsjob.go index 0a8ee6d19..da5af695c 100644 --- a/pkg/attestation/crafter/runners/jenkinsjob.go +++ b/pkg/attestation/crafter/runners/jenkinsjob.go @@ -1,5 +1,5 @@ // -// Copyright 2023 The Chainloop Authors. +// Copyright 2024 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -55,7 +55,10 @@ func (r *JenkinsJob) ListEnvVars() []*EnvVarDefinition { {"GIT_COMMIT", true}, // Some info about the agent - {"AGENT_WORKDIR", false}, + // We've found this one to be optional + {"AGENT_WORKDIR", true}, + // Workspace is required as long as the jobs run inside a `node` block + {"WORKSPACE", false}, {"NODE_NAME", false}, } } diff --git a/pkg/attestation/crafter/runners/jenkinsjob_test.go b/pkg/attestation/crafter/runners/jenkinsjob_test.go index 7eae1480e..9d83ea56d 100644 --- a/pkg/attestation/crafter/runners/jenkinsjob_test.go +++ b/pkg/attestation/crafter/runners/jenkinsjob_test.go @@ -1,5 +1,5 @@ // -// Copyright 2023 The Chainloop Authors. +// Copyright 2024 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -82,7 +82,8 @@ func (s *jenkinsJobSuite) TestListEnvVars() { {"BUILD_URL", false}, {"GIT_BRANCH", true}, {"GIT_COMMIT", true}, - {"AGENT_WORKDIR", false}, + {"AGENT_WORKDIR", true}, + {"WORKSPACE", false}, {"NODE_NAME", false}, }, s.runner.ListEnvVars()) } @@ -98,7 +99,7 @@ func (s *jenkinsJobSuite) TestResolveEnvVars() { os.Unsetenv("GIT_COMMIT") resolvedEnvVars, errors = s.runner.ResolveEnvVars() s.Empty(errors) - s.Equal(reuiredJenkinsJobTestingEnvVars, resolvedEnvVars) + s.Equal(requiredJenkinsJobTestingEnvVars, resolvedEnvVars) } func (s *jenkinsJobSuite) TestRunURI() { @@ -119,19 +120,19 @@ func (s *jenkinsJobSuite) SetupTest() { } var jenkinsJobTestingEnvVars = map[string]string{ - "JOB_NAME": "some-jenkins-job", - "BUILD_URL": "http://some-build-url/", - "AGENT_WORKDIR": "/home/sample/agent", - "NODE_NAME": "some-node", - "GIT_BRANCH": "somebranch", - "GIT_COMMIT": "somecommit", + "JOB_NAME": "some-jenkins-job", + "BUILD_URL": "http://some-build-url/", + "WORKSPACE": "/home/sample/agent", + "NODE_NAME": "some-node", + "GIT_BRANCH": "somebranch", + "GIT_COMMIT": "somecommit", } -var reuiredJenkinsJobTestingEnvVars = map[string]string{ - "JOB_NAME": "some-jenkins-job", - "BUILD_URL": "http://some-build-url/", - "AGENT_WORKDIR": "/home/sample/agent", - "NODE_NAME": "some-node", +var requiredJenkinsJobTestingEnvVars = map[string]string{ + "JOB_NAME": "some-jenkins-job", + "BUILD_URL": "http://some-build-url/", + "WORKSPACE": "/home/sample/agent", + "NODE_NAME": "some-node", } // Run the tests