Jenkins管道冒出shell退出代码以使阶段

时间:2017-02-24 00:44:26

标签: jenkins groovy jenkins-pipeline

Absolute Jenkins管道/ groovy noob在这里,我有一个舞台

stage('Building and Deploying'){
    def build = new Build()
    build.deploy()
}

使用共享库,Build.groovy的来源在这里:

def deploy(branch='master', repo='xxx'){
    if (env.BRANCH_NAME.trim() == branch) {
        def script = libraryResource 'build/package_indexes/python/build_push.sh'
        // TODO: Test out http://stackoverflow.com/questions/40965725/jenkins-pipeline-cps-global-lib-resource-file-for-shell-script-purpose/40994132#40994132
        env.PYPI_REPO = repo
        sh script
    }else {
        echo "Not pushing to repo because branch is: "+env.BRANCH_NAME.trim()+" and not "+branch
    }
}

问题是当未能将构建推送到远程仓库时(见下文),该阶段仍然显示成功。

running upload
Submitting dist/xxx-0.0.7.tar.gz to https://xxx.jfrog.io/xxx/api/pypi/grabone-pypi-local
Upload failed (403): Forbidden
...
Finished: SUCCESS

如何冒泡shell脚本的退出代码并使舞台失败?

1 个答案:

答案 0 :(得分:0)

再次偶然发现了这个问题,结果证明是Python版本问题,我记不清Python的确切版本但是在setuptools中是一个问题,IIRC将Python升级到2.7.1x修复了它。