Search code examples
shellvue.jscommand-lineazure-devopssentry

How to access an environment variable from a pipeline and pass it to a release pipeline


I have an application that builds and deploys automatically.

Current flow:

Git push -> Azure (build) pipeline creates artifact -> Azure Release pipeline picks up artifact and deploys it on a DigitalOcean server using "copy files" and then goes into the command line.

I need to do some automatic configuration in the commandline that needs an environment variable that is unique for each build.

How can I access an environment variable from the pipeline and somehow pass it into the release pipeline so that I can use it in the commands in the commandline?

NPM command used that exports the environment variable:

  "releasecustom": "export VUE_APP_SENTRY_RELEASE=$(UniqueValue) && node 
   scripts/createreleasesentry.js && npm run build && node scripts/finalizereleasesentry.js",

Solution

  • I'm a bit afraid that this is not supported out of the box. What you can do is to write down your values in file useing powershell task for instance (or use extension for this).

    New-Item -Path $(Build.ArtifactStagingDirectory)/vardrop -Name "variables.txt" -ItemType "file" -Value "This is a text string."
    

    Then you have to publish this as an artifact.

    - task: PublishBuildArtifacts@1
      inputs:
        pathToPublish: '$(Build.ArtifactStagingDirectory)/vardrop'
        artifactName: vardrop
    

    As next in release pipeline you need to download artifact and read this file and set variable (using powershell task).

    You have here an example, but if you have in file more values than a one you need to split them and assign separately.

    echo "##vso[task.setvariable variable=dp]$(cat $(System.ArtifactsDirectory)/vardrop/variables.txt)"