microsoft / azure-pipelines-extensions

Collection of all RM and deployment extensions
http://www.visualstudio.com/explore/release-management-vs
MIT License
275 stars 425 forks source link

Service Now Change Management - Transmitting Change Request Number as an Output Variable Between Stages. #1207

Open hmtmh opened 7 months ago

hmtmh commented 7 months ago

Is it possible to designate "Change_Request_Number" as an output variable in a YAML pipeline, similar to the approach used in a classic release pipeline?

This is how it is being done in classic release pipeline. image

We aim to use the Change Request Number in a subsequent stage to perform an update on the corresponding change request.

image

aczarkowski commented 6 months ago

I have been looking at the same thing. You don't need to do that at all. UpdateServiceNowChangeRequest@2 task will query for the change request number first if not provided. It will get the change request number created by the approval gate (uses some correlation id behind the scenes to query for it). If you want to know the value of change request then the same UpdateServiceNowChangeRequest@2 will create output variable with the same name (CHANGE_REQUEST_NUMBER) which you can then easily retrieve in the next job or stage. See my example:

  - job: update_change_request
    dependsOn: 
      - calculate_parameters
    pool: server
    variables:
      PlannedStartDate: $[ dependencies.calculate_parameters.outputs['calculate_parameters.plannedStartDate'] ]
      PlannedEndDate: $[ dependencies.calculate_parameters.outputs['calculate_parameters.plannedEndDate'] ]
    steps:
      - task: UpdateServiceNowChangeRequest@2
        name: update_change_request
        inputs:
          ServiceNowConnection: 'ServiceNowTestBasicAuth'
          WorkNotes: 'This is a test'
          otherParameters: |
            {
              "u_justification": "Test",
              "u_risk_impact_analysis": "Test",
              "u_implementation_plan": "Test",
              "u_backout_plan": "Test",
              "u_test_plan": "Test"
            }

  - job: display_change_request
    dependsOn: 
      - update_change_request
    pool:
      vmImage: 'ubuntu-latest'
    variables:
      ChangeRequestNumber: $[ dependencies.update_change_request.outputs['update_change_request.CHANGE_REQUEST_NUMBER'] ]
    steps:
      - task: PowerShell@2
        inputs:
          targetType: 'inline'
          script: |
            Write-Host "Change Request Number: $(ChangeRequestNumber)"
      - bash: echo "##vso[task.setvariable variable=CHANGE_REQUEST_NUMBER;isOutput=true]$(ChangeRequestNumber)"
        name: set_output_variable