仅在请求请求时,如何在Jenkins中运行舞台? [英] How do I run a stage in Jenkins only on pull request?

查看:59
本文介绍了仅在请求请求时,如何在Jenkins中运行舞台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个基于Jenkinsfile的管道,其中包含多个阶段,每次对Github的提交都由webhook触发.我想在每次提交时都保持构建"和单元测试"阶段运行,但是只有在分支为拉取请求启动时才运行集成测试"阶段.

I have a Jenkinsfile-based pipeline with several stages in it right now that is triggered by webhook on every commit to Github. I'd like to keep the "build" and "unit tests" stages running on every commit, but ONLY run the "integration tests" stage when the branch is up for pull request.

我想要什么:

stage("build)"{
    // runs every commit
}
stage("unit tests"){
    // runs every commit
}
stage("integration tests"){
    // runs ONLY on pull request
}

我一直无法找到解决方案,有什么想法吗?

I've been unable to find a solution to this, any ideas?

推荐答案

在#jenkins IRC频道中提问后,我被指出了正确的方向.可以使用 https://wiki.jenkins.io /display/JENKINS/SCM + Filter + Branch + PR + Plugin

After asking in the #jenkins IRC channel I was pointed in the right direction. This is possible using the https://wiki.jenkins.io/display/JENKINS/SCM+Filter+Branch+PR+Plugin

脚本管道:

if(env.CHANGE_ID) {
// do something because it's a pull request
} else {
// not a pull request
}

声明性管道:

pipeline {
stages {
    stage('Example Deploy') {
        when {
            allOf {
                environment name: 'CHANGE_ID', value: ''
                branch 'master'
            }
        }
        steps {
            // not a pull request so do something
        }
    }
}

}

这篇关于仅在请求请求时,如何在Jenkins中运行舞台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆