Search code examples
azurejenkinsjenkins-groovyacr

Set environment variable in Jenkins from command output


Is it possible to set the output of a command to an environment variable in Jenkins? Something like this:

environment{
  ... 
  ...
  registryAddress=sh(az acr list --query "[?contains(name, 'myname')].name" --output tsv --resource-group myresourcegroup))
}

Solution

  • Yes, it is possible. You will need to use returnStdout: true when calling sh.
    registryAddress=sh(script: "<your-script>", returnStdout: true)