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

Time:12-16

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?

CodePudding user response:

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

CodePudding user response:

try:

export CHECK=curl -sI https://somegithuburl.com; echo $CHECK the curl command should be placed between ``

  • Related