简体   繁体   English

Jenkins 管道 Groovy 脚本未在工作区中执行

[英]Jenkins Pipeline Groovy script not executing in workspace

I have a Jenkins that runs in a container.我有一个在容器中运行的 Jenkins。 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.我试图调试在 Jenkins 管道中运行的 groovy 文件,发现由于某种原因它没有从工作区执行。 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. shell 命令按预期返回已签出存储库的列表。 However same command executed in groovy script shows container root filesystem.然而,在 groovy 脚本中执行的相同命令显示容器根文件系统。 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. sh节点是一个正确的 Jenkins 内置步骤,它在作业中运行命令。

The .execute() is a bit of a hack:) .execute()有点乱:)
You're running the Groovy script through the Jenkins interpreter, which is not pretty standard and does it's own thing.您正在通过 Jenkins 解释器运行 Groovy 脚本,这不是很标准并且它自己做事。

I'd avoid it and keep with the Jenkins sh that has a standard behaviour.我会避免它并与具有标准行为的 Jenkins sh保持一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM