Open hmtmh opened 12 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
@aczarkowski Thanks for the yaml it helped me big time, I was really excited after finding your yaml. I have another question
I am using environment approvals and check at the prod deploy stage to check if the change ticket created during the dev stage is in a certain status now my question is how do I pass the change record number dynamically in the environment at the approvals and checks so that the valdation can be done on the exact change which was created during the dev stage.
I am a beginer in yaml and ado so I would really appriciate all you inputs here thanks.
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.
We aim to use the Change Request Number in a subsequent stage to perform an update on the corresponding change request.