BAEL-3746:- Get the Output of a Shell Command Executed Using Into a Variable in Jenkins Pipeline (#13544)
This commit is contained in:
parent
463a5d4dc5
commit
444cc4ac2d
@ -0,0 +1,13 @@
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Example') {
|
||||
steps {
|
||||
script {
|
||||
def output = sh(script: "echo \$(ls)", returnStdout: true)
|
||||
echo "Output: ${output}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Example') {
|
||||
steps {
|
||||
script {
|
||||
def output = sh(returnStdout: true, script: 'pwd')
|
||||
echo "Output: ${output}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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}'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user