我正在使用Jenkins声明性管道,我想根据git分支部署我的应用程序。甚至在Jenkins中的分支信息以及条件匹配时,Jenkins都说:*“由于条件而跳过了部署到开发阶段”与分支测试时的测试分支相同。我该如何解决这个问题?
注意:当我将代码推送到开发或测试分支时,可以触发设置为* / develop,* / test,* / master和Jenkins等项目配置设置的分支。
stage('Deploy to dev'){
when{
beforeAgent true
anyOf{
branch "origin/develop"
}
}
stage('Deploy to staging'){
when{
beforeAgent true
anyOf{
branch "origin/test"
}
}
控制台输出
+refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/develop
Seen branch in repository origin/master
Seen branch in repository origin/test
Seen 3 remote branches
> git show-ref --tags -d # timeout=10
Checking out Revision 5ebda79eb3a50a578786e75587f7d92dfc399122 (origin/develop)
[Pipeline] { (Deploy to dev)
Stage "Deploy to dev" skipped due to when conditional
Stage "Deploy to staging" skipped due to when conditional
答案 0 :(得分:1)
是否定义了变量BRANCH_NAME?
<form onsubmit="parent.scrollTo(0, 0); return true">
步骤使用此变量。
您是否使用了(github)多分支插件来自动设置此变量? 进行println以查看是否已定义。
设置此变量,这是我在构建阶段所做的
when