-
Bug
-
Resolution: Fixed
-
Low
-
9.2.14, 9.6.5, 10.2.0
-
None
-
1
-
Severity 3 - Minor
-
Issue Summary
Bamboo plan with the below configuration for example:
First Stage:
- First stage > First job: Main script task that creates a variable injection file
- First Stage > First job > Final tasks: the final Inject Bamboo Variables task reads the file and injects the variables in the RESULT scope.
Final Stage:
- Final Stage > Final Job > Dump variables to log Task
- Final Stage > Final Job > Script task to print the injected variable created from the First stage > First Job > Final tasks.
When using the below REST API to stop a Job in the build plan(which has multiple stages and tasks) that has injected variable task in the final tasks of the first stage > first job, the injected variables are not passed to the Final Stage > Final Job task.
Rest API endpoint: DELETE /api/latest/queue/<proj-plan-job-key>
curl --request DELETE --url 'http://{baseurl}/rest/api/latest/queue/{projectKey}-{buildKey}-{buildNumber}'
This is reproducible on Data Center:
Steps to Reproduce
- Create a plan in Bamboo with below configuration:
stages: - First Stage: manual: false final: false jobs: - First Job - second stage: manual: false final: false jobs: - Second Job - Final Stage: manual: false final: true jobs: - Final Job First Job: key: JOB1 tasks: - script: interpreter: SHELL scripts: - |- echo "Running first job" echo "Creating environment file..." echo "injectedVar=presentnew" > injectedVars.env echo "Environment file created." echo "File content: $(cat injectedVars.env)" echo "Job Done. Sleep 20s." sleep 20 description: echo final-tasks: - inject-variables: file: injectedVars.env scope: RESULT namespace: inject description: injectVars - any-task: plugin-key: com.atlassian.bamboo.plugins.bamboo-variable-inject-plugin:dump configuration: {} description: debug artifact-subscriptions: [] Second Job: key: SJ tasks: - script: interpreter: SHELL scripts: - |- echo "Running second job" echo "injectedVar Value: ${bamboo_inject_injectedVar}" description: echo artifact-subscriptions: [] Final Job: key: FJ tasks: - any-task: plugin-key: com.atlassian.bamboo.plugins.bamboo-variable-inject-plugin:dump configuration: {} description: debug - script: interpreter: SHELL scripts: - |- echo "Running final job" echo "injectedVar Value: ${bamboo_inject_injectedVar}"
- Run the build plan.
- Stop the JOB1 under First Stage > First Job after the "Environment file created" through REST API:
curl -X DELETE -u admin:sphere --url "https://linux-88805.prod.atl-cd.net/bamboo/rest/api/latest/queue/<PROJ-PLAN-JOB-Buildkey>"
Replace <PROJ-PLAN-JOB-Buildkey> with the build job key
Expected Results
Injected variables created in the RESULT scope through Final tasks in previous stages should be passed to the next Final stages in the build plan when the build stopped through REST API.
When we stop the build job manually from the Bamboo UI, injected variables are stored and passed to the Final stages.
Actual Results
The final tasks in the initial stage create injected variables and can be seen in build logs that a variable is being injected, but in the final stage, the injected variable is not stored and passed and shows an empty value.
Build logs:
27-Dec-2024 11:05:39 Starting task 'injectVars' of type 'com.atlassian.bamboo.plugins.bamboo-variable-inject-plugin:inject' 27-Dec-2024 11:05:39 Injected variable bamboo.inject.injectedVar=presentnew in RESULT scope 27-Dec-2024 11:05:39 Finished task 'injectVars' with result: Success
27-Dec-2024 11:05:21 Running final job 27-Dec-2024 11:05:21 injectedVar Value:
Workaround
Instead of using the DELETE rest API call to stop the build job, use the below Struts call to stop the build job:
curl --user <user_name>:<password> -X POST "<Bamboo_URL>/build/admin/stopPlan.action?planResultKey=<Build-job-key>" -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Atlassian-Token: no-check'
Replace respective values in the above for the <user_name>,<password>,<Bamboo_URL>,<Build-job-key>
This will stop the build the way we stop manually from the UI and update the build details in the backend, and inject variables will be available for the next stages.