Capturing The Return Value Of The JFROG CLI in a jenkins pipeline

Hi,

Im trying to capture the return value of a jfrog-cli command ( using the jenkins jfrog cli plugin ) in a pipeline script, the TARGET variable is a filename on the remote artifactory which either exists or doesn’t… I’d expect data to return a count, but all it returns is null, can anyone help?

def data = jf 'rt s ${TARGET} --count'

The console output shows the following… but 1 isn’t assigned to the variable

12:10:33 [Info] Searching artifacts...
12:10:35 [Info] Found 1 artifact.
1

Additionally Capturing the resultant object…

[linuxDebian] /home/jenkins/tools/io.jenkins.plugins.jfrog.JfrogInstallation/jfrog-cli/jf rt s {TARGET} --count
13:03:46 [Info] Searching artifacts…
13:03:47 [Info] Found 1 artifact.
1
[Pipeline] echo
class org.codehaus.groovy.runtime.NullObject

Jenkins setup:
Using jenkins 2.414.2 and the latest version of the jfrog cli plugin.

Hi @steelhead31 and welcome to this community. :wave:

The issue you’re encountering might be related to how Jenkins handles the return values of shell commands, especially when executed within a pipeline.
In Jenkins pipeline scripts, the return value of a shell command isn’t as directly accessible as you might expect in a typical shell script.
Instead, the result of a shell command is treated as the standard output, and you need to capture and process it accordingly.
Well, at least, that’s the way I think I understand it, I don’t know the JFrog plugin, so it may or may not use the underlying

Here’s how I think you could capture and process the result of your jfcommand thanks to the shell:

def result = sh(script: "jf rt s ${TARGET} --count", returnStatus: true)
if (result == 0) {
    echo "The command succeeded."
} else {
    echo "The command failed with exit code ${result}."
}

// If you want to capture the standard output of the command
def output = sh(script: "jf rt s ${TARGET} --count", returnStdout: true).trim()
echo "Command output: ${output}"

Make sure that the jf command is available in the environment where the Jenkins pipeline runs and that it’s in the system’s PATH.

I have similar issue. The problem is that I don’t have control to install jf on the Jenkins node. I installed jf using global tool jfrog-cli hence I can only call `jf using similar like

def myData = jf ‘rt s blabla’

is there anyway to capture the result of myData?

I’ve had the same problem, and managed to get around it by using the Pipeline Utility Steps plugin. This provides a ‘tee’ block that records the output of commands within to a specified file which can then be manipulated with something like a python script.

My pipeline looked similar to below:

pipeline {
    stages {
        stage('Pipeline Step'){
            steps {
                script {
                    tee('search_output.txt'){
                        jf "rt s --spec spec-file.json "
                    }
                    sh "python3 search_manipulator.py -i search_output.txt"
                }
            }
        }
    }
}