I have a Jenkins that runs in a container. I was trying to debug a groovy file that is running in Jenkins pipeline and found out it is not executing from the workspace for some reason. Below is the Jenkins pipeline
pipeline {
agent any
stages {
stage('testing') {
steps {
script {
sh '''
ls
'''
def proc = [ "ls"].execute()
def output = proc.text
println(output)
}
}
}
}
}
The shell command returns listing of the checked out repository, as expected. However same command executed in groovy script shows container root filesystem. That's not what I expected. What is going on here?
Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (testing)
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ ls
README.md
docs
jenkins
modules
scripts
[Pipeline] echo
aws
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
vault
The sh
node is a proper Jenkins built-in step that runs the command in the job.
The .execute()
is a bit of a hack:)
You're running the Groovy script through the Jenkins interpreter, which is not pretty standard and does it's own thing.
I'd avoid it and keep with the Jenkins sh
that has a standard behaviour.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.