Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins 如何在文件中的函数中运行多个sh命令?_Jenkins_Jenkins Pipeline - Fatal编程技术网

Jenkins 如何在文件中的函数中运行多个sh命令?

Jenkins 如何在文件中的函数中运行多个sh命令?,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,给定以下文件: @NonCPS void touchFiles() { sh "touch foo" sh "touch bar" } node('general') { touchFiles() sh "ls" } 我在Jenkins的控制台日志中看到以下内容: Running on box35 in /internal/slave/build/workspace/1499786637.EXAMPLE_test-repo_test_jenkinsfile

给定以下文件:

@NonCPS
void touchFiles() {
    sh "touch foo"
    sh "touch bar"
}

node('general') {
    touchFiles()

    sh "ls"
}
我在Jenkins的控制台日志中看到以下内容:

Running on box35 in /internal/slave/build/workspace/1499786637.EXAMPLE_test-repo_test_jenkinsfile
[Pipeline] {
[Pipeline] sh
[1499786637.EXAMPLE_test-repo_test_jenkinsfile] Running shell script
+ touch foo
[Pipeline] sh
[1499786637.EXAMPLE_test-repo_test_jenkinsfile] Running shell script
+ ls
foo
请注意,尚未创建“栏”

为什么只有第一个
sh
在这里运行?如何在一个文件中计算出一系列
sh
调用


(我知道我可以编写
sh“touch foo;touch bar”
,但在更复杂的Jenkins文件中,有时我需要单独的
sh
调用。)

尝试一个sh命令并连接参数:

@NonCPS
void touchFiles() {
    sh "touch foo;" +
       "touch bar"
}

node('general') {
    touchFiles()

    sh "ls"
}

除了@arifCee的答案外,您还可以这样做:

@NonCPS
void touchFiles() {
    sh '''
    touch foo
    touch bar
    '''
}

node('general') {
    touchFiles()

    sh "ls"
}

这是事实,但有时我需要运行单独的
sh
命令。