Update Jira Issues with on prem Jira and Octopus Deploy

I need to update ou jira issues when they are deployed and since we can not use the jira deploy plugin, I need to create my own process using the jira API. I am having issues on how to get the issues when deploying. We publish all the build metadata to octopus from TC for every package we deploy but seems using the Octopus.Release.Package in a powershell step seems to have no data. The same variable in the release notes template seems to be working fine. Can you give me some guidance on how to do this??

Thanks Trent

Hi tbielejeski,

Sorry to hear you’re running into trouble. What syntax are you using when referencing the Octopus.Release.Package variable within a step? Can you try referencing it using the following format? #{Octopus.Action[StepName].Package.PackageId} where StepName is the name of the step in which the package is being deployed, and PackageId is the information you want to reference? Please let me know if that works for you or if you need more assistance.

Thanks,
Jeremy

here is what the shared step looks like

if($null -ne $OctopusParameters[“Octopus.Release.Package”])
{
foreach($package in $OctopusParameters[“Octopus.Release.Package”])
{
foreach($WorkItemLink in $package.WorkItems)
{
write-host "workItem.Id " $WorkItemLink.Id
}
}
}

Hi tbielejeski,

Instead of using Octopus.Release.Package, would you be able to give Octopus.Deployment.Changes a try? Here is a document outlining the system variable: https://octopus.com/docs/projects/variables/system-variables#deployment-changes

Using this variable should give you the results you’re looking for. Please let me know if it works or if you need further help.

Thanks,
Jeremy

Yep it seems to have the data I need

Thanks

You’re very welcome, I’m glad to hear you got it working.

Sincerely,
Jeremy

Well Maybe I spoke to soon.

So once I have that data I now need to get to the workitems inside the buildinfomation object for a single package and It seems to always be empty even though the build info tab shows workitems for that package

Below is my code
if($null -ne $OctopusParameters[“Octopus.Deployment.Changes”])
{
$jsonData = ConvertFrom-Json -InputObject $OctopusParameters[“Octopus.Deployment.Changes”]

foreach($change in $jsonData)
{
   Write-host " ----------------------Begin----------------------------------------- "
   Write-host "Release Changes " 
   Write-Host $change
   Write-host "-----------------------End---------------------------------------- "
   foreach($buildInformation in $change.BuildInformation)
   { 
   
     if($buildInformation.PackageId -eq $OctopusParameters["Octopus.Action.Package[Package].PackageId"])
     {
       Write-host " ----------------------Begin----------------------------------------- "
       Write-host "Build Info " 
       Write-host $buildInformation
       Write-host "-----------------------End---------------------------------------- "
       Write-host " ----------------------Begin----------------------------------------- "
       Write-host "Build Info Package " 
       Write-host $buildInformation.PackageID
       Write-host "-----------------------End---------------------------------------- "
       foreach($workItemLink in $buildInformation.WorkItems)
       {
            Write-host " ----------------------Begin----------------------------------------- "
            Write-host "Build WorkItems" 
            Write-host $workItemLink
            Write-host "-----------------------End---------------------------------------- "
            write-host "Issue " $workItemLink.Id $comment 
              #add_comment $headerInfo $WorkItemLink.Id $comment
       }
     }
   }
  break
}

Hi Tbielejeski,

I took a look at your code and an example JSON and I think I found the issue. The work items you are looking for are actually outside of BuildInformation inside of another section called WorkItems(Workitems are in both places, but empty within BuildInformation).

Here is an example of how Octopus.Deployment.Changes is structured. It will show why you are finding the item you’re referencing is empty.

[
  {
    "Version": "2020.05.15.97",
    "ReleaseNotes": "\n- randomquotes-js 1.0.200515.1333\n\n    - [RQJ-2](https://octopussamples.atlassian.net/browse/RQJ-2) - Jeremy Miller, comment for issue\n\n",
    "BuildInformation": [
      {
        "PackageId": "randomquotes-js",
        "Version": "1.0.200515.1333",
        "BuildEnvironment": null,
        "BuildNumber": 140,
        "BuildUrl": "https://bitbucket.org/octopussamples/randomquotes-js/addon/pipelines/home#!/results/140",
        "Branch": "master",
        "VcsType": "Git",
        "VcsRoot": "http://bitbucket.org/octopussamples/randomquotes-js",
        "VcsCommitNumber": "91d693f",
        "VcsCommitUrl": null,
        "WorkItems": [],
        "Commits": []
      }
    ],
    "WorkItems": [
      {
        "Id": "RQJ-2",
        "LinkUrl": "https://octopussamples.atlassian.net/browse/RQJ-2",
        "Source": "Jira",
        "Description": "Jeremy Miller, comment for issue"
      }
    ],
    "Commits": [
      {
        "Id": "91d693fcaa4a8a6de5b18e814ede2a7c40b2a8b5",
        "LinkUrl": "http://bitbucket.org/octopussamples/randomquotes-js/commits/91d693fcaa4a8a6de5b18e814ede2a7c40b2a8b5",
        "Comment": "RQJ-2 - Really want to get workitems in samples"
      }
    ]
  }
]

The easiest way to see all of the variables and information available to you is to enable variable logging. Here is a link explaining it: https://octopus.com/docs/support/how-to-turn-on-variable-logging-and-export-the-task-log. It’s not recommended to keep this enabled forever, it’s best just to use it to figure out issues/processes, as it can slow down your deployment.

Once you’ve done this you will be able to see all of the information laid out for you in your verbose/raw log.

Please let me know if this helps and you’re able to get your script working or if you need more assistance.

Thanks,
Jeremy

So Been doing a lot of testing and my main problem is I only want the work items tied to the changes for that release number. Seems the
Octopus.Deployment.Changes gives me all the changes since the last release to that environment. Seems I would have to do some release number compares and then just take the items from a single package, since all the packages have the work item links.
I ended up just calling the api for a package and getting the worksites from the build info that way.

Hi Tbielejeski,

At first I thought you might be able to use Octopus.Deployment.WorkItems , but that has the same issue, in that it will contain a unique list of workitems for potentially multiple releases (as the deployment changes are rolled-up). I’ll raise this internally to see if there are any alternatives to using an API call to get the information you need.

Thanks,
Jeremy

Hi Tbielejeski,

I spoke with an engineer regarding this and he told me that this behavior is by design. He said that the changes array should always be in order so you can formulate your logic in your powershell script to get the desired behavior. For example if you have multiple releases worth of changes and you want to get the workitem from the last one, you could find the length of the array and then just output the last entry in the array. Of course if your API call is working I would hate to complicate things with more testing/implementation, but I wanted to give you more information/options.

Please feel free to reach out with any questions or concerns.

Thanks,
Jeremy

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.