使用Jenkins,多配置构建的现代最佳实践是什么?
我想支持多个分支和多个配置。
例如,对于我要构建定位的软件的每个版本V1,V2 平台P1和P2。
我们设法建立了多分支的声明式管道。每个构建都有自己的docker,因此可以轻松支持多个平台。
pipeline {
agent none
stages {
stage('Build, test and deploy for P1) {
agent {
dockerfile {
filename 'src/main/docker/Jenkins-P1.Dockerfile'
}
}
steps {
sh buildit...
}
}
stage('Build, test and deploy for P2) {
agent {
dockerfile {
filename 'src/main/docker/Jenkins-P2.Dockerfile'
}
}
steps {
sh buildit...
}
}
}
}
这提供了一个涵盖多个平台的工作,但每个平台没有单独的红色/蓝色状态。 有一个很好的论点,那就是,这无关紧要,因为除非构建适用于所有平台,否则您不应该发布该版本。
但是,我希望每种配置都有单独的状态指示器。这表明我应该使用一个多配置构建,该构建为每个配置触发一个参数化的构建,如下所示(以及linked question):
pipeline {
parameters {
choice(name: 'Platform',choices: ['P1', 'P2'], description: 'Target OS platform', )
}
agent {
filename someMagicToGetDockerfilePathFromPlatform()
}
stages {
stage('Build, test and deploy for P1) {
steps {
sh buildit...
}
}
}
}
这有几个问题:
这也引出了一个问题:声明性管道中的参数有什么用?
有没有一种可以兼顾两方面的策略,即:
答案 0 :(得分:2)
这是部分答案。我认为其他具有更好经验的人将可以对此进行改进。
目前未经测试。我可能正在吠错树。 请发表评论或添加更好的答案。
除非需要用户输入,否则不要使用管道参数
使用脚本化和声明性管道的混合体 (另请参见https://stackoverflow.com/a/46675227/1569204)
具有一个根据参数声明管道的函数: (另请参见https://jenkins.io/doc/book/pipeline/shared-libraries/)
使用节点在管道中(至少在蓝色海洋中)创建可见的指示器
类似以下内容:
def build(string platform) {
switch(platform) {
case P1:
dockerFile = 'foo'
indicator = 'build for foo'
break
case P2:
dockerFile = 'bar'
indicator = 'build for bar'
break
}
pipeline {
agent {
dockerfile {
filename "$dockerFile"
}
node {
label "$indicator"
}
}
stages {
steps {
echo "build it"
}
}
}
}
答案 1 :(得分:0)
我认为最干净的方法是将所有内容都与您介绍的第一个类似,并在管道中进行,我在这里看到的唯一修改是将它们并行化,因此您实际上将尝试针对两个平台进行构建/测试。 / p>
要重用上一阶段的工作空间,您可以执行以下操作:reuseNode true
App.js:8 GET http://localhost:3001/download/test.pdf net::ERR_CONNECTION_REFUSED
Uncaught (in promise) TypeError: Failed to fetch