Home > Enterprise >  Set environment variable in Jenkins from command output
Set environment variable in Jenkins from command output

Time:09-17

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))
}

CodePudding user response:

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

  • Related