- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个 Jenkins 服务器,每当(php 或 java)项目具有有效的 pom.xml 时,使用 jenkins-build-per-branch 从 git 同步。我们使用 Maven 版本控制策略来管理我们的 Artifact ,并使用 git-flow 作为分支策略/工具。我们还尽可能使用 jenkins 选项“每当构建 SNAPSHOT 依赖项时构建”。
我们遇到的问题是在构建 -SNAPSHOT 人工制品时 - 一切都乱七八糟,一切都想立即构建。 (构建“开发”-SNAPSHOT 会导致所有下游“功能”和“开发”分支开始)
理想情况下,我们希望找到一些方法,当 jenkins 启动下游作业时,我们不会在功能构建和开发构建之间交叉授粉。
有人试过吗?像 Conditional+BuildStep+Plugin 这样的东西会有帮助吗? https://wiki.jenkins-ci.org/display/JENKINS/Conditional+BuildStep+Plugin
最佳答案
这是一个老问题,但在 6 年后仍然适用。 Build whenever a SNAPSHOT dependency is built
设置上有一个“threshold”字段,可以控制触发哪些构建
来自pipeline-maven-plugin README :
Threshold based on the Maven lifecycle phase reached in the Mavenbuild of the upstream job (package, install, deploy). By default, onlythe maven builds who reach the deploy phase will trigger downstreambuilds.
例如,在脚本管道的 withMaven()
中,您可以使用 lifecycleThreshold: 'deploy'
设置一个 pipelineGraphPublisher
,例如:
withMaven(
maven: MAVEN_VERSION,
jdk: JAVA_VERSION,
mavenOpts: MAVEN_OPTS,
globalMavenSettingsConfig: globals.MAVEN_SETTINGS_ID,
options: [
pipelineGraphPublisher(
lifecycleThreshold: 'deploy',
includeSnapshotVersions: true
)
]) {
sh("mvn ${PHASE}")
}
然后任何执行生命周期阶段下方 deploy
(例如package
或install
)的 SNAPSHOT 构建将 < em>不 触发下游作业。请注意,deploy
已经是默认设置,因此该示例不是特别有用,但它展示了如何使用该设置,您可能希望将其设置到另一个阶段。
第一部分已经完成,但现在您需要一种方法来有条件地为您确实想要触发下游构建的构建执行不同的 Maven 生命周期阶段您不想触发下游构建。我们根据分支名称执行此操作,以便 Pull Request 和 Release 分支不会触发上游包:
/**
* Return the correct Maven goal for the current branch
*
* Because the pipelineGraphPublisher's lifecycleThreshold in the withMaven() call above is set to 'deploy', pipelines
* that run the 'install' goal will not trigger downstream jobs; this helps us minimize superfluous Jenkins builds:
*
* https://github.com/jenkinsci/pipeline-maven-plugin/blob/master/README.adoc#trigger-downstream-pipeline-when-a-snapshot-is-built
*/
String getGoalForCurrentBranch() {
if ( env.BRANCH_NAME ==~ /(^PR-(\d+)$)|(^releases\/v.*)/ ) {
echo("Pull Request or release branch detected! Executing Maven 'install' goal rather than 'deploy' goal to avoid triggering downstream Jenkins jobs")
return 'install'
}
return 'deploy'
}
然后您可以在执行 mvn
的任何地方调用此 getGoalForCurrentBranch()
方法以确定执行哪个生命周期阶段:
withMaven(
...
sh("mvn ${getGoalForCurrentBranch()}")
)
大多数分支将执行 mvn deploy
并且将触发下游 Jenkins 作业,但 Pull Request 分支将执行 mvn install
并将 不触发下游作业。
需要注意的是,您可能还有其他依赖于某些生命周期阶段的东西。在上面的示例中,Pull Request 分支 Artifact 不会部署到您的 Artifact 存储库(例如 Nexus)。在我们的例子中,这实际上是所需的行为,但您需要确定什么是您可以接受的,并相应地调整您的阈值。
关于maven - 限制在 SNAPSHOT 依赖项上触发哪些下游构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27298359/
我正在使用 Jenkins 进行持续集成。我创建了单独的 View ,例如服务器 A 的 View A 、服务器 B 的 View B 等。 每个 View 都会根据服务器的环境属性构建我的项目。 但
我有以下伪代码: var queue = new BufferBlock(new DataflowBlockOptions { BoundedCapacity = 5 }); var a = new
我想这样做,但是在 Jenkins DSL 中: 如果在某个地方找到了这个,但它不工作: job('ps-first') { steps { shell('echo "landing"') }
我们的 API 中有一个路由(在调用时)会访问另一个第 3 方 API。 例如 HTTP-GET/account/1 这会从我们的数据库返回一些数据,并从.. 说 .. 像 Auth0/Okta/Sa
我是一名优秀的程序员,十分优秀!