How to retrieve the completion status and associated info for each task in a Bamboo deployment

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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

 

Purpose

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.


tip/resting Created with Sketch.

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:

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.

(info) 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:

curl -k -u admin:pwdadmin http://localhost/bamboo/rest/api/latest/deploy/result/${bamboo.versionid}?includeLogs=true  

(warning) 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

 "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
  }
}  






Last modified on Feb 27, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.