Does anyone know how to set the description text for a job defined in scripted or declarative pipeline in Jenkins ? Reason: I want to add some meaningful text (small documentation) about the job.
Declarative pipelines break down stages into individual stages that can contain multiple steps. Scripted pipelines use Groovy code and references to the Jenkins pipeline DSL within the stage elements without the need for steps.
You just have to use params. [NAME] in places where you need to substitute the parameter. Here is an example of a stage that will be executed based on the condition that we get from the choice parameter. The parameter name is ENVIRONMENT , and we access it in the stage as params.
Hi, The Declarative pipeline is a new feature that is added to create the pipeline. This is basically written in a Jenkinsfile which can be stored into a source code management system such as Git.
In pipeline as code technique, jobs are created using a script file that contains the steps to be executed by the job. In Jenkins, that scripted file is called Jenkinsfile. In this Jenkins tutorial, we will deep dive into Jenkins Declarative Pipeline with the help of Jenkins declarative pipeline examples.
Jenkins Scripted Pipeline corresponds to the option “Pipeline Script” when selecting Pipeline Definition. You write your script in text field in job configuration, or copy/paste your script to it. It is a rather easier way to try your first pipeline.
Jenkins declarative pipeline should be the preferred way to create a Jenkins job as they offer a rich set of features, come with less learning curve & no prerequisite to learn a programming language like Groovy just for the sake of writing pipeline code. We can also validate the syntax of the Declarative pipeline code before running the job.
The majority of DevOps Engineers and Developers interact with Jenkins in their day-to-day activities. Jenkins is an automation tool that helps developers and DevOps to build, test and deploy applications. Nowadays, people prefer to use Jenkins pipelines to set up build, test, and deployment workflow over freestyle jobs.
This solution changes the description of a job item via a groovy script in jenkins. I only used it in a freestyle job, but i think it should be also working in an scripted pipeline:
import jenkins.model.*
final jenkins = Jenkins.getInstanceOrNull()
final myJob = jenkins.getItem("MyJobName")
description = "<h1 style=\"color:green\">The newest build has number ${env.BUILD_NUMBER}</h1>"
myJob.setDescription(description)
myJob.save()
This solution changes the description of a build: Use 'currentbuild' global variable.
I.e. declarative pipeline:
script { currentbuild.description = 'New Description' }
Works the same in scripted pipelines :)
Reference: https://opensource.triology.de/jenkins/pipeline-syntax/globals
for declarative pipeline
script {
currentBuild.description = "description env var if required :${env.ver}"
}
for scripted
currentBuild.description = "description env var if required :${env.ver}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With