Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$class syntax in jenkins scripted dsl

Often when looking at scripted jenkins pipeline code, I see this pattern...

step([$class: 'GitHubSetCommitStatusBuilder',
        statusMessage: [content: 'Pipeline Started']])

I have not had any luck finding documentation on this technique and would love it if someone could explain what this is doing and when/why it is useful. I believe this is a way to instantiate and populate the members of an underlying groovy class - but more detail would be appreciated.

Also is this documented anywhere?

like image 424
T-Lo Avatar asked Feb 14 '18 22:02

T-Lo


People also ask

What is $class in Jenkins pipeline?

Here is a reference that briefly explains the syntax. Basically, you are providing the step() function a map of arguments in the form of name-value pairs. The first argument which is especially denoted by the name $class tells the function which class (plugin) to instantiate.

What syntax does the scripted pipeline in Jenkins follows?

Scripted Pipeline: Ideally, Scripted pipeline is written in Jenkins file on web UI of Jenkins. Unlike Declarative pipeline, the scripted pipeline strictly uses groovy based syntax. Since this, The scripted pipeline provides huge control over the script and can manipulate the flow of script extensively.

What syntax does Jenkins use?

A Jenkinsfile can be written using two types of syntax - Declarative and Scripted. Declarative and Scripted Pipelines are constructed fundamentally differently.


Video Answer


1 Answers

Here is a reference that briefly explains the syntax. Basically, you are providing the step() function a map of arguments in the form of name-value pairs. The first argument which is especially denoted by the name $class tells the function which class (plugin) to instantiate.

It also seems that this syntax is being deprecated in favor of shorter syntax, also explained in the same link.

like image 63
amahfouz Avatar answered Oct 16 '22 09:10

amahfouz