How to retrieve the completion status and associated info for each task in a Bamboo deployment
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
This method that we are going to refer to now uses the 'Final Task' in the deployment to trigger a dedicated plan. It has a plan's job to fetch the status of each task that was run during the deployment. The advantage of this approach is that we can parse the output logs and use the information for several purposes. For example, we can update Jira with the status of the deployment and the status of each individual task. If a failure occurs, we can determine which task caused the error.
The benefit of using a single plan to retrieve and parse the logs to later update Jira lies in its reusability. You can establish multiple deployments and reuse the same plan to update Jira every time, provided that the script to parse the results is robust enough. This strategy encourages efficiency and consistency across all your deployments.
Environment
The implementation was tested on version 9.2.4, but it's likely to function with other versions as well.
Solution
Step 1 - Add a final Task
In the final task you should add this script task:
1
2
versionid=$(echo ${bamboo.resultsUrl} | sed 's/.*= *//')
curl -k -u admin:pwdadmin -X POST "http://localhost/bamboo/rest/api/latest/queue/PROJ-NX?bamboo.variable.versionid=${versionid}"
Here's an explanation of what the command does:
versionid=$(echo ${bamboo.resultsUrl} | sed 's/.*= *//')`:
This shell command assigns the value of the variable `versionid`. It takes the value of the `bamboo.resultsUrl` variable, prints it, and then pipes that output to `sed`, the stream editor.
The `sed 's/.*= *//'` command is a regular expression that removes everything before and including the equals sign (=).
The end result is that `versionid` gets the value of the `bamboo.resultsUrl` after the equals sign.
ℹ️ In essence, we're extracting the versionid from the URL and using it to trigger a Plan named PROJ-NX (replace this with your actual plan name) and passing that variable as a parameter
Step 2 - Dedicated Plan to Retrieve logs:
In the newly created plan, a script task is required. This task will retrieve all the result information for the deployment using the following command:
1
curl -k -u admin:pwdadmin http://localhost/bamboo/rest/api/latest/deploy/result/${bamboo.versionid}?includeLogs=true
⚠️ Subsequently, you will need to parse the data you wish to extract using another script task. Then, create the command to target the Jira instance with the desired information. This will create the update discussed in our initial example.
Below is a sample output of that command, showcasing a single task that completed successfully
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
"log": "Finished task 'Done' with result: Success"
{
"deploymentVersion": {
"id": 14843905,
"name": "release-5",
"creationDate": 1693843765719,
"items": [
{
"id": 14909441,
"name": "Arti",
"planResultKey": {
"key": "BIP-PLANKEY2-4",
"entityKey": {
"key": "BIP-PLANKEY2"
},
"resultNumber": 4
},
"type": "BAM_ARTIFACT",
"artifact": {
"id": 14778369,
"label": "Arti",
"size": 39,
"isSharedArtifact": true,
"isGloballyStored": false,
"linkType": "com.atlassian.bamboo.plugin.artifact.handler.local:ServerLocalArtifactHandler",
"planResultKey": {
"key": "BIP-PLANKEY2-4",
"entityKey": {
"key": "BIP-PLANKEY2"
},
"resultNumber": 4
},
"archiverType": "NONE"
}
}
],
"operations": {
"canView": true,
"canViewConfiguration": true,
"canEdit": true,
"canDelete": true,
"allowedToExecute": false,
"canExecute": false,
"allowedToCreateVersion": true,
"allowedToSetVersionStatus": true
},
"planBranchName": "master",
"ageZeroPoint": 1702302409411,
"deploymentProjectId": 6389761
},
"deploymentVersionName": "release-5",
"id": 25755649,
"deploymentState": "SUCCESS",
"lifeCycleState": "FINISHED",
"startedDate": 1702292009375,
"queuedDate": 1702292009465,
"executedDate": 1702292009765,
"finishedDate": 1702292613971,
"reasonSummary": "Manual run by <a href=\"http://localhost/bamboo/browse/user/bamboo\">bamboo</a>",
"key": {
"key": "6389761-6586369-25755649",
"entityKey": {
"key": "6389761-6586369"
},
"resultNumber": 25755649
},
"agent": {
"id": 17268737,
"name": "Local",
"type": "LOCAL",
"active": true,
"enabled": true,
"busy": false
},
"operations": {
"canView": true,
"canViewConfiguration": true,
"canEdit": true,
"canDelete": true,
"allowedToExecute": true,
"canExecute": true,
"allowedToCreateVersion": false,
"allowedToSetVersionStatus": false
},
"logFiles": [
"http://localhost/bamboo/deployment-download/6586369/build_logs/6389761-6586369-25755649.log"
],
"logEntries": {
"size": 619,
"logEntry": [
{
"log": "582",
"unstyledLog": "582",
"date": 1702292595000,
"formattedDate": "11-Dec-2023 11:03:15",
"cssStyle": "buildOutputLog"
},
{
"log": "583",
"unstyledLog": "583",
"date": 1702292596000,
"formattedDate": "11-Dec-2023 11:03:16",
"cssStyle": "buildOutputLog"
},
{
"log": "584",
"unstyledLog": "584",
"date": 1702292597000,
"formattedDate": "11-Dec-2023 11:03:17",
"cssStyle": "buildOutputLog"
},
{
"log": "585",
"unstyledLog": "585",
"date": 1702292598000,
"formattedDate": "11-Dec-2023 11:03:18",
"cssStyle": "buildOutputLog"
},
{
"log": "586",
"unstyledLog": "586",
"date": 1702292599000,
"formattedDate": "11-Dec-2023 11:03:19",
"cssStyle": "buildOutputLog"
},
{
"log": "587",
"unstyledLog": "587",
"date": 1702292600000,
"formattedDate": "11-Dec-2023 11:03:20",
"cssStyle": "buildOutputLog"
},
{
"log": "588",
"unstyledLog": "588",
"date": 1702292601000,
"formattedDate": "11-Dec-2023 11:03:21",
"cssStyle": "buildOutputLog"
},
{
"log": "589",
"unstyledLog": "589",
"date": 1702292602000,
"formattedDate": "11-Dec-2023 11:03:22",
"cssStyle": "buildOutputLog"
},
{
"log": "590",
"unstyledLog": "590",
"date": 1702292603000,
"formattedDate": "11-Dec-2023 11:03:23",
"cssStyle": "buildOutputLog"
},
{
"log": "591",
"unstyledLog": "591",
"date": 1702292604000,
"formattedDate": "11-Dec-2023 11:03:24",
"cssStyle": "buildOutputLog"
},
{
"log": "592",
"unstyledLog": "592",
"date": 1702292605000,
"formattedDate": "11-Dec-2023 11:03:25",
"cssStyle": "buildOutputLog"
},
{
"log": "593",
"unstyledLog": "593",
"date": 1702292606000,
"formattedDate": "11-Dec-2023 11:03:26",
"cssStyle": "buildOutputLog"
},
{
"log": "594",
"unstyledLog": "594",
"date": 1702292607000,
"formattedDate": "11-Dec-2023 11:03:27",
"cssStyle": "buildOutputLog"
},
{
"log": "595",
"unstyledLog": "595",
"date": 1702292608000,
"formattedDate": "11-Dec-2023 11:03:28",
"cssStyle": "buildOutputLog"
},
{
"log": "596",
"unstyledLog": "596",
"date": 1702292609000,
"formattedDate": "11-Dec-2023 11:03:29",
"cssStyle": "buildOutputLog"
},
{
"log": "597",
"unstyledLog": "597",
"date": 1702292610000,
"formattedDate": "11-Dec-2023 11:03:30",
"cssStyle": "buildOutputLog"
},
{
"log": "598",
"unstyledLog": "598",
"date": 1702292611000,
"formattedDate": "11-Dec-2023 11:03:31",
"cssStyle": "buildOutputLog"
},
{
"log": "599",
"unstyledLog": "599",
"date": 1702292612000,
"formattedDate": "11-Dec-2023 11:03:32",
"cssStyle": "buildOutputLog"
},
{
"log": "VariableGlobal2 20",
"unstyledLog": "VariableGlobal2 20",
"date": 1702292613000,
"formattedDate": "11-Dec-2023 11:03:33",
"cssStyle": "buildOutputLog"
},
{
"log": "Finish",
"unstyledLog": "Finish",
"date": 1702292613000,
"formattedDate": "11-Dec-2023 11:03:33",
"cssStyle": "buildOutputLog"
},
{
"log": "Finished task 'Done' with result: Success",
"unstyledLog": "Finished task 'Done' with result: Success",
"date": 1702292613000,
"formattedDate": "11-Dec-2023 11:03:33"
},
{
"log": "Finalising the build...",
"unstyledLog": "Finalising the build...",
"date": 1702292613000,
"formattedDate": "11-Dec-2023 11:03:33"
},
{
"log": "Stopping timer.",
"unstyledLog": "Stopping timer.",
"date": 1702292613000,
"formattedDate": "11-Dec-2023 11:03:33"
},
{
"log": "Build 6389761-6586369-25755649 completed.",
"unstyledLog": "Build 6389761-6586369-25755649 completed.",
"date": 1702292613000,
"formattedDate": "11-Dec-2023 11:03:33"
},
{
"log": "Finished processing deployment result Deployment of 'release-5' on 'Test'",
"unstyledLog": "Finished processing deployment result Deployment of 'release-5' on 'Test'",
"date": 1702292614000,
"formattedDate": "11-Dec-2023 11:03:34"
}
],
"start-index": 594,
"max-result": 25
}
}
Was this helpful?