Shared Jenkins Library returns the result of sh command instead of actual result

20 Views Asked by At

What I have:

  • Jenkins declarative multi-branch pipeline, which uses the my custom library.
  • Simple library function which performs some actions with commits messages.

Code and problem description:

Simplified declarative pipeline

@Library('<my-library>@<specific-version>') _

pipeline {
    options {
        timeout(time: 30)
    }

    agent {
        label "<agent>"
    }
    
    stages {
    <...>
       stage('Problem stage'){
            steps{
                script {
                  result = libraryFunctionCall()
                }
            }
    <...>
       }
    }    
}

Simplified library function:

@NonCPS
def call() {
    <definitions and checks, works fine>
    def result = "test"
    def data = getData(param)
    
    result = < some calculation based on received data >

    return result
}

@NonCPS
def getData(param) {
    return sh(returnStdout: true,
            script: """
                    curl < ... >
            """).trim()
}

Problem: Library function returns the result of sh command, not the actual calculated result

Versions:

  • Jenkins 2.401.1
  • Pipeline Utility Steps 2.15.4

Thanks for any help!

0

There are 0 best solutions below