Felipe
Felipe

Reputation: 340

How to save a command output to a variable in a Jenkinsfile Shell step?

I have the following code:

...

stage('Some stage') {
    sh """
        #!/bin/bash
        CHECK=$(curl -sI https://somegithuburl.com)
        
        echo $CHECK
    """
}
...

And when the Jenkins job is executed it returns:

+ CHECK=

Do you know how can I save the output in a variable in the same way I would do in a Shell script?

Upvotes: 0

Views: 2204

Answers (2)

hakik ayoub
hakik ayoub

Reputation: 65

try:

export CHECK=`curl -sI https://somegithuburl.com`;
echo $CHECK

Upvotes: 1

Ron
Ron

Reputation: 6591

Correct way to pull the output and save as a variable:

export CHECK="$(curl -s https://somegithuburl.com)"

then you can use $CHECK as a variable

Upvotes: 3

Related Questions