Azure DevOps Deployment Job not finding registered variable during run

Viewed 48

I am trying to use an Azure DevOps deployment job to create a ServiceNow Standard Change Request, register the sys_id to the pipeline, then use it in subsequent phases of the Deployment Job. I have a Python utility that creates a Change Request, and filters the sys_id registering it as a variable. I can access said variable in the same "phase" of the Deployment Job, but the next phase is not working as expected, well,the docs don't really cover any use like this other than contrived uses. I think I was following the Set Variables in Scripts See my pipeline below.

                - task: Bash@3
                  name: snow
                  displayName: Create Standard RFC from Template
                  # This task, I'm registering the SYS_ID of the RFC being created. I want to use this throughout the rest
                  # of the Deployment Job.
                  inputs:
                    targetType: inline
                    script: |
                      export sys_id=$(servicenow standard create template $(std_tmpl_sys_id) --query="result.sys_id.value")
                      echo "##vso[task.setvariable variable=rfc_sys_id;isoutput=true]$sys_id"
                  env:
                    SNOW_USER: '$(SNOW_USER)'
                    SNOW_PASS: '$(SNOW_PASS)'
                - task: Bash@3
                  displayName: Progress RFC to Scheduled
                  # This works, for this one task.
                  inputs:
                    targetType: inline
                    script: |
                      servicenow standard update $(snow.rfc_sys_id) state=Scheduled
                  env:
                    SNOW_USER: '$(SNOW_USER)'
                    SNOW_PASS: '$(SNOW_PASS)'
            deploy:
              steps:
                - task: Bash@3
                  displayName: Install ServiceNow
                  inputs:
                    targetType: inline
                    script: |
                      pip install snow --index-url=https://azure:$(System.AccessToken)@pkgs.dev.azure.com/$(ADO_ORG)/$(ADO_PROJ)/_packaging/python-azure-artifacts/pypi/simple/
                - task: Bash@3
                  displayName: Progress RFC to Implement
                  # Here, I attempt to get the registered variable from the preDeploy "phase" and use it as a Shell Variable
                  # because otherwise Azure DevOps would try to just execute it as a shell command.
                  inputs:
                    targetType: inline
                    script: |
                      servicenow standard update ${RFC_SYS_ID} state=Implement
                  env:
                    SNOW_USER: '$(SNOW_USER)'
                    SNOW_PASS: '$(SNOW_PASS)'
                    RFC_SYS_ID: $[ dependencies.BuildPythonApp.outputs['preDeploy.rfc_sys_id'] ]

Also found here:

Is it even possible to do this in Azure DevOps YAML Pipelines using a Deployment Job?

1 Answers

Can you try two of them? I think only the step-name is missing.

RFC_SYS_ID: $[ dependencies.BuildPythonApp.outputs['preDeploy.snow.rfc_sys_id'] ]

or

RFC_SYS_ID: $[ dependencies.BuildPythonApp.outputs['BuildPythonApp.snow.rfc_sys_id'] ]
Related