How do I make a Jenkins build monitor for a wall screen?
Have each stage of the pipeline record whether it passed, then write a board file in a post step that always runs, and copy it somewhere a browser can read. No Jenkins plugin is involved.
The Jenkinsfile
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'make build'
}
post {
success { script { env.BUILD_STATE = 'ok' } }
failure { script { env.BUILD_STATE = 'bad' } }
}
}
stage('Test') {
steps {
sh 'make test'
}
post {
success { script { env.TEST_STATE = 'ok' } }
failure { script { env.TEST_STATE = 'bad' } }
}
}
stage('Deploy') {
steps {
sh 'make deploy'
}
post {
success { script { env.DEPLOY_STATE = 'ok' } }
failure { script { env.DEPLOY_STATE = 'bad' } }
}
}
}
post {
always {
// A stage that never ran has no state, so it is drawn idle.
sh '''
cat > board.json <<EOF
{
"title": "$JOB_BASE_NAME",
"tag": "Build # $BUILD_NUMBER",
"nodes": [
{ "id": "build", "label": "Build", "state": "${BUILD_STATE:-idle}" },
{ "id": "test", "label": "Test", "state": "${TEST_STATE:-idle}", "after": ["build"] },
{ "id": "deploy", "label": "Deploy", "state": "${DEPLOY_STATE:-idle}", "after": ["test"] }
]
}
EOF
aws s3 cp board.json s3://your-bucket/board.json --content-type application/json --cache-control no-cache
'''
}
}
}How it works
- Each stage has its own
postblock that recordsokorbadin an environment variable. - When a stage fails, Jenkins skips the stages after it. Their variables are never set, so the shell falls back to
idleand those orbs stay grey. - The
post { always { } }block at the end runs whether the build passed, failed or was aborted. It writes the file and uploads it.
The result is a row of orbs, one for each stage, joined by arrows:
{
"title": "checkout",
"tag": "Build # 3082",
"nodes": [
{ "id": "build", "label": "Build", "state": "ok" },
{ "id": "test", "label": "Test", "state": "bad", "after": ["build"] },
{ "id": "deploy", "label": "Deploy", "state": "idle", "after": ["test"] }
]
}Where the file goes
The example copies the file to Amazon S3, which needs the AWS command line tool and credentials on the agent. Any of the places to host a board file will do.
The browser on the monitor reads the file from that place, not from Jenkins. Jenkins itself can stay behind your firewall, and the monitor needs no Jenkins login.
Showing more on each orb
Add fields to a node in the same way as state. To show when a stage last ran, set a time in the stage's post block and use it as since with a caption of "Last ran". To show a build as unstable rather than failed, record warn in the stage's unstable block.
One board for many jobs
A board file describes one board, so each pipeline that writes one has its own address. On a multibranch pipeline, put $BRANCH_NAME in the file name to get a board for each branch.
To put many jobs on one wall as a grid, use a small script on a timer instead. It asks Jenkins for the last build of each job, at /job/NAME/lastBuild/api/json, and writes one node for each:
| Jenkins says | State |
|---|---|
building is true | run, blue |
result is SUCCESS | ok, green |
result is UNSTABLE | warn, amber |
result is FAILURE | bad, red |
result is ABORTED or NOT_BUILT | idle, grey |
Writing a board file in any language has a starting point for that script in six languages.
Related questions
-
How do I build a CI/CD pipeline dashboard for the office wall?
Give each stage of the pipeline a node, say what it comes after, and have the last step of the pipeline write the file. The wall then shows where a change has got to and where it stopped.
-
Does FluxGlow work with GitLab CI, CircleCI, Buildkite or Azure Pipelines?
Yes. FluxGlow has no integrations, so there are none to wait for. Any CI system that can run a shell command at the end of a pipeline can write a board file and upload it.
-
Where can I host a board file?
Anywhere that serves the file over https, lets other websites read it, and does not cache it for long. A storage bucket, a public GitHub repository or a web server you already run will all do.