[英]How can I better visualize the work of a large build step using a Jenkinsfile?
I have a pretty long build step (it takes hours) and a Jenkinsfile triggering it. 我有一个相当长的构建步骤(需要几个小时),并且有一个Jenkinsfile触发它。 (The build steps consists of multiple Makefile targets etc.)
(构建步骤包括多个Makefile目标等)
Since the build step does everything needed to produce the artifact, the Jenkins Pipeline visualization is pretty useless. 由于构建步骤完成了生成工件所需的一切,因此Jenkins Pipeline可视化几乎没有用。
Is there a way how I can better visualize the internals of the build step without porting/duplicating it to a Jenkinsfile ? 有没有一种方法可以更好地可视化构建步骤的内部结构而无需将其移植/复制到Jenkinsfile?
You can move away from a single target task to build everything ( make
or make all
) and instead specifically target different build tasks in the Jenkinsfile. 您可以离开单个目标任务来构建所有内容(
make
或make all
),而可以专门针对Jenkinsfile中的不同构建任务。 For example, let's say you're building an app for different platforms. 例如,假设您要为不同的平台构建应用程序。 Your original Jenkinsfile might be...
您最初的Jenkinsfile可能是...
node('builder') {
stage('build') {
sh "make"
}
}
which was triggering the "all" target in your makefile, which might be triggering the tasks "iOS", "android", and "windowsphone" 这会触发您的makefile中的“所有”目标,这可能会触发任务“ iOS”,“ android”和“ windowsphone”
Instead, have your Jenkinsfile target each one of these make tasks individually. 相反,让您的Jenkinsfile分别针对每个make任务。
Ex: 例如:
node('builder') {
stage('build iOS') {
sh "make iOS"
}
stage('build android') {
sh "make android"
}
stage('build windows phone') {
sh "make windowsphone"
}
}
By splitting up your target tasks into these multiple stages, you should better reporting in your Jenkins UI. 通过将目标任务划分为多个阶段,您应该更好地在Jenkins UI中进行报告。
If you wanted to be really brave, you could avoid hardcoding this in two places (the all
target, and the Jenkinsfile) by creating a script to take apart what all
was doing and turn it into jenkins stages. 如果您真的很勇敢,可以通过创建脚本来分解
all
工作并将其转变为jenkins阶段,从而避免在两个地方( all
目标和Jenkinsfile)进行硬编码。 Assuming that your all
or default task is just a list of other tasks, you can use the following bash: 假设您的
all
或默认任务只是其他任务的列表,则可以使用以下bash:
if [[ -z $(make -rpn | grep ".DEFAULT_GOAL") ]]; then
DEFAULTTARGET=all
else
DEFAULTTARGET=$(make -rpn | grep ".DEFAULT_GOAL" | sed "s/.*=[[:space:]]*//" | tr -d "[:space:]")
fi
make -rpn | sed -n -e "/^$/ { n ; /^[^ ]*:/p ; }" | grep "$DEFAULTTARGET:" | sed "s/.*:[[:space:]]*//" | tr " " "\n"
in a Jenkinsfile like so: 在这样的Jenkinsfile中:
node() {
## NOT NORMALLY REQUIRED. Just sets up a simple makefile
sh "echo 'all: images release clean report' > Makefile "
## Start of required logic
def makeTasks = sh(script: 'if [[ -z $(make -rpn | grep ".DEFAULT_GOAL") ]]; then DEFAULTTARGET=all; else DEFAULTTARGET=$(make -rpn | grep ".DEFAULT_GOAL" | sed "s/.*=[[:space:]]*//" | tr -d "[:space:]"); fi; make -rpn | sed -n -e "/^$/ { n ; /^[^ ]*:/p ; }" | grep "$DEFAULTTARGET:" | sed "s/.*:[[:space:]]*//" | tr " " "\n"', returnStdout: true)
def tasks = makeTasks.split('\n')
for(int i = 0; i < tasks.size(); i++ ){
stage(tasks[i]) {
echo tasks[i]
// This will fail with the bogus makefile defined above, but would work with a real one.
// sh 'make ${tasks[i]}'
}
}
}
Not really: there was a similar issue for long-running stages . 并非完全如此: 长时间运行阶段也存在类似问题 。
Regarding steps, there is JENKINS 33185 ("Visualize parallel steps within a Pipeline Stage") still open 关于步骤,仍有JENKINS 33185 (“可视化管道阶段中的并行步骤”)
But for one single long-running step, all you have is the shell output, which is not that helpful when a command takes a long time to complete. 但是对于一个单独的长时间运行的步骤,您所拥有的只是shell输出,当命令需要很长时间才能完成时,它就没有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.