0

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))
}
lo labs
  • 89
  • 13

1 Answers1

2

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

Melkjot
  • 498
  • 3
  • 13
  • 1
    Thanks it works, this is what I was looking for. Here the details for the docs: https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script – lo labs Sep 17 '21 at 11:15