Jenkins Pipeline job can't find script due to @tmp path being created

后端 未结 6 1068
小蘑菇
小蘑菇 2021-02-07 07:19

I am writing a pipeline job that will call another script to execute. The Jenkinsfile and script exist in the same directory and yet the job fails to find the script to run.

6条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 08:21

    I was having the same issue. I think @Oren technically answered your question about why Jenkins creates this tmp space, but I can share some info about how I solved it.

    Basically, my Jenkins host symlinks bin/sh to dash; not bash. So, using a POSIX-compliant shell script solved the issue for me.

    For example, I was trying to use shopt -s extglob to do some pattern matching:

    stage {
        def shellCommand = $/ "rm -rf ! (_data|_includes|_plugins|Gemfile|_config.yml|page-builder)"/$
        sh(returnStdout: true, script: shellCommand).trim()
    }
    

    Since dash doesn't support extglob, replacing that with a POSIX-compliant find command worked:

    stage {
        sh('find . -regextype posix-extended -not -regex ".*includes.*|.*data.*|.*plugins.*|.*config.yml|.*Gemfile.*"')
    } 
    

提交回复
热议问题