BAEL-3746:- Get the Output of a Shell Command Executed Using Into a Variable in Jenkins Pipeline (#13544)

This commit is contained in:
Kapil Khandelwal 2023-02-27 23:19:45 +05:30 committed by GitHub
parent 463a5d4dc5
commit 444cc4ac2d
4 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,13 @@
pipeline {
agent any
stages {
stage('Example') {
steps {
script {
def output = sh(script: "echo \$(ls)", returnStdout: true)
echo "Output: ${output}"
}
}
}
}
}

View File

@ -0,0 +1,17 @@
pipeline {
agent any
stages {
stage('Example') {
steps {
script {
def status = sh(returnStatus: true, script: 'ls /test')
if (status != 0) {
echo "Error: Command exited with status ${status}"
} else {
echo "Command executed successfully"
}
}
}
}
}
}

View File

@ -0,0 +1,13 @@
pipeline {
agent any
stages {
stage('Example') {
steps {
script {
def output = sh(returnStdout: true, script: 'pwd')
echo "Output: ${output}"
}
}
}
}
}

View File

@ -0,0 +1,13 @@
pipeline {
agent any
stages {
stage('Example') {
steps {
script {
def output = sh(returnStdout: true, returnStdoutTrim: true, script: 'echo " hello "')
echo "Output: '${output}'"
}
}
}
}
}