Skip to content

[Eng]: Are there Azure Powershell commands that help create ADO items? #26956

Closed
@suneetsasidharan

Description

@suneetsasidharan

Description

We're using something like the following snippet for creating and auto linking a work item to a PR in the build pipeline. We're curious if there is a Azure Powershell command that achieves the same without adding "az" into the mix in the pipeline.

steps:
- powershell: |
Write-Host "Installing Azure CLI extensions..."
az extension add --name azure-devops

            displayName: 'Install Azure CLI Extensions'
            env:
              AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
            condition: always()
          - powershell: |
              Write-Host "Checking for associated work items..."
              $workItems = az boards work-item relation list --id $(Build.BuildId) --query "[?rel=='System.LinkTypes.Hierarchy-Reverse'].target.id" -o tsv
              if (-not $workItems) {
                Write-Host "No associated work items found. Creating a new work item..."
                $prTitle = az repos pr show --id $(System.PullRequest.PullRequestId) --query "title" -o tsv
                $workItem = az boards work-item create --title "$prTitle" --type "Bug" --description "This work item was created because no work item was associated with build $(Build.BuildId)." --assigned-to "$(Build.RequestedFor)" --area "Outlook Web\Native Host" --query "id" -o tsv
                Write-Host "Linking work item $workItem to the pull request..."
                az repos pr work-item add --id $(System.PullRequest.PullRequestId) --work-items $workItem
              } else {
                Write-Host "Associated work items found: $workItems"
              }
            displayName: 'Check, Create, and Link Work Item'
            env:
              AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
            condition: always()

Metadata

Metadata

Assignees

No one assigned

    Labels

    customer-reportedfeature-requestThis issue requires a new behavior in the product in order be resolved.needs-author-feedbackMore information is needed from author to address the issue.no-recent-activityThere has been no recent activity on this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions