'Groovy execute shell script and capture output

I need to set an environment variable from a Groovy script, the value of the env var should be produced with the AWS CLI, my command

def proc ='aws codeartifact get-authorization-token --region=eu-central-1 --domain companyname --domain-owner accountnumber --query authorizationToken --output text'.execute()
env.CODEARTIFACT_AUTH_TOKEN = proc.in.text

But I get an error message

10:59:47  Caused: java.io.IOException: Cannot run program "aws": error=2, No such file or directory

I am new to Groovy and looking around for solutions, any tips in the meanwhile?



Solution 1:[1]

Your path variable maybe wrong. Check it by

println System.getenv('PATH')

then fix it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James Graham