EducationPerfect / azure-jira-update

Update Jira with Azure Deployment Information
MIT License
21 stars 17 forks source link

Error: Associations must provide at least one value. #6

Open booyaa opened 2 years ago

booyaa commented 2 years ago

Output from DevOps

2021-11-16T23:09:32.3549810Z ##[section]Starting: Update JIRA status
2021-11-16T23:09:32.3560493Z ==============================================================================
2021-11-16T23:09:32.3561398Z Task         : PowerShell
2021-11-16T23:09:32.3562156Z Description  : Run a PowerShell script on Linux, macOS, or Windows
2021-11-16T23:09:32.3563062Z Version      : 2.194.0
2021-11-16T23:09:32.3563699Z Author       : Microsoft Corporation
2021-11-16T23:09:32.3564531Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2021-11-16T23:09:32.3565420Z ==============================================================================
2021-11-16T23:09:32.4938693Z Generating script.
2021-11-16T23:09:32.4980409Z ========================== Starting Command Output ===========================
2021-11-16T23:09:32.5001748Z [command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/home/vsts/work/_temp/2b1d2e8b-b13a-45f1-8c0c-b08571eae222.ps1'
2021-11-16T23:09:33.2519096Z VERBOSE: Exporting function 'Add-JiraDeploymentInformation'.
2021-11-16T23:09:33.2521368Z VERBOSE: Exporting function 'Update-AzureDeploymentInformation'.
2021-11-16T23:09:34.8173089Z [Deployment Reponse] {
2021-11-16T23:09:34.8174818Z   "acceptedDeployments": [],
2021-11-16T23:09:34.8175809Z   "rejectedDeployments": [
2021-11-16T23:09:34.8176668Z     {
2021-11-16T23:09:34.8177481Z       "key": {
2021-11-16T23:09:34.8178345Z         "pipelineId": "53",
2021-11-16T23:09:34.8179235Z         "environmentId": "19",
2021-11-16T23:09:34.8180180Z         "deploymentSequenceNumber": 1637104174
2021-11-16T23:09:34.8181106Z       },
2021-11-16T23:09:34.8181931Z       "errors": [
2021-11-16T23:09:34.8182930Z         {
2021-11-16T23:09:34.8183959Z           "message": "Associations must provide at least one value."
2021-11-16T23:09:34.8184965Z         }
2021-11-16T23:09:34.8185767Z       ]
2021-11-16T23:09:34.8186556Z     }
2021-11-16T23:09:34.8187331Z   ],
2021-11-16T23:09:34.8188166Z   "unknownIssueKeys": [],
2021-11-16T23:09:34.8189072Z   "unknownAssociations": []
2021-11-16T23:09:34.8189902Z }
2021-11-16T23:09:34.8270906Z 
2021-11-16T23:09:34.8307083Z acceptedDeployments rejectedDeployments               unknownIssueKeys unknownA
2021-11-16T23:09:34.8316425Z                                                                        ssociati
2021-11-16T23:09:34.8317823Z                                                                        ons
2021-11-16T23:09:34.8319517Z ------------------- -------------------               ---------------- --------
2021-11-16T23:09:34.8320674Z {}                  {@{key=; errors=System.Object[]}} {}               {}
2021-11-16T23:09:34.8327720Z 
2021-11-16T23:09:34.9076348Z ##[section]Finishing: Update JIRA status

Steps to reproduce

This is primarily to help others who need to access the internal (private) functions in this excellent plugin.

Usage

$DebugPreference="Continue"

$Features = Import-Module (Join-Path ".." "azure-jira-update" "EP.PowerShell.JiraDeployInfo") -PassThru # Allows us to access the private functions in this module

$SystemAccessToken = $env:SYSTEM_TOKEN # can use your Personal Access Token
$AzureChangeUrl = "$env:SYSTEM_COLLECTIONURI/$env:SYSTEM_TEAMPROJECT/_traceability/runview/changes?currentRunId=$($env:BUILD_BUILDID)&__rt=fps"

$jiraIds = @()
$jiraIds += ( & $Features `
                { 
                        param($SystemAccessToken, $AzureChangeUrl) 
                        Get-JiraIDsFromAzureChanges -SystemAccessToken $SystemAccessToken -AzureChangeUrl $AzureChangeUrl 
                } `
                -SystemAccessToken $SystemAccessToken -AzureChangeUrl $AzureChangeUrl )
$jiraIds

Useful docs

Notes

I'm going to see if I can test the PowerShell scripts locally using the build values from a previous pipeline run. Any pointers would be appreciated.

booyaa commented 2 years ago

Noticed that #4 has changed how deploymentSequenceNumber is computed. So I'm retesting just in case this resolves the issue.

mwheeler-ep commented 2 years ago

I think this usually happens when there's no JIRA like issues listed under the changes section - which might be related to how branches are cut for release so changes aren't detected by Azure DevOps

I'd be nice to know what the Azure DevOps GUI says under changes image image

booyaa commented 2 years ago

Here you go, I guess that explain our problem. I think my colleague grabbed the merge commit hence all the other commits with the Jira ticket info is missing. I'm going to do more testing to see if I can reproduce in my test pipeline. Previously all I've done created a release branch off main, which is probably why it worked for me, but not in our app pipeline.

image

booyaa commented 2 years ago

I'm probably going to repurpose/replace the private function Get-AzureDevOpsBuildChanges to do output something like this git log --pretty=oneline --abbrev-commit main...releases/a.b.c ugly, but it would get us the vital Jira ticket info that vanishes in the related changes view for the pipeline run.

We've been running a fork (to enable debugging), I'll let you know our progress. Not ideal, but gets our team out of a tight spot at the moment.

From what I've been reading (the DevOps REST API is a nightmare to navigate) endpoint to list changes doesn't handle GitHub repos correctly. The other alternative is to look at the change history in the Environments.

booyaa commented 2 years ago

@mwheeler-ep just thought I'd through this one out there, what branch strategy do you use at EducationPerfect? We merge the feature branch into "main" (which deploys to dev) and then we cut a "release" branch off main (which deploys to staging and prod environments).

mwheeler-ep commented 2 years ago

I think the first version I wrote of this did a git log .... It's not a bad idea :) For some of our repos we also cut release branches and I think run into the same issue.

booyaa commented 2 years ago

I've written the code, it's a bit of a hack 😢 we're going to test in our environment, if it proves successful I'd be happy to create a PR if it might be useful to others.

voidsstr commented 2 years ago

I've also run into this issue - with the master code as of this week, the path $build_changes = $response.fps.dataProviders.data.'ms.vss-traceability-web.traceability-run-changes-data-provider'.artifactsData.data did not match to a real path in the devops '_tracability' url. So I modified that to use the 'artifact id' data in my fork and that seems to work when the branch being built has a jira id in it, but does not work when PRing from a feature branch to a develop branch or release branch. Are there any other areas in the devops data that we can pull more reliable jira IDs?

galinski-n commented 2 years ago

I've also hit this issue. Any good solutions discovered?