Jenkins: Trigger Multi-branch pipeline on upstream change

大憨熊 提交于 2019-11-28 17:35:01
cscutcher

I'm currently trying to get this to work for our deployment. The closest I've got is adding the following to the downstream Jenkinsfile;

properties([
    pipelineTriggers([
        triggers: [
            [
                $class: 'jenkins.triggers.ReverseBuildTrigger',
                upstreamProjects: "some_project", threshold: hudson.model.Result.SUCCESS
            ]
        ]
    ]),
])

That at least gets Jenkins to acknowledge that it should be triggering when 'some_project' get's built i.e it appears in the "View Configuration" page.

However so far builds of 'some_project' still don't trigger the downstream project as expected.

That being said maybe you'll have more luck. Let me know if it works for you.

(Someone else has asked a similar question Jenkins multi-branch pipeline and specifying upstream projects )

Japster24

If you're using a declarative multi-branch pipeline, you can use:

triggers {
  upstream(upstreamProjects: "some_project/some_branch", threshold: hudson.model.Result.SUCCESS)
}

If you wish for branch matching to occur across dependencies you can use:

triggers {
  upstream(upstreamProjects: "some_project/" + env.BRANCH_NAME.replaceAll("/", "%2F"), threshold: hudson.model.Result.SUCCESS)
}

Pipeline Job configuration still natively supports Build Triggers, including reverse build trigger, Build after other projects are built. You can even specify a branch from Pipeline Multi-branch project.

Unfortunately reverse triggering is not available Pipeline Multi-branch jobs. The closest you can get to reverse triggering is by using Promoted Builds Plugin. But it still doesn't let you configure per branch setup.

Additionally Snippet Generator clarifies:

The following variables are currently unavailable inside a Pipeline script:

NODE_LABELS WORKSPACE SCM-specific variables such as SVN_REVISION

ps. Maybe the only way would be to prompt from upstream to downstream.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!