Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have an entire declarative pipeline defined and parameterized in a shared library?

Essentially I want my Jenkinsfile to look something like this:

@Library('my-descriptive-pipline') _
myPipeline('arg1','arg2','arg3')

Then my shared library (/vars/descriptivePipeline.groovy) would look like this:

pipeline {
    agent any
    options {
      skipDefaultCheckout()
    }
    environment {
    }
    stages {
        stage('stageA') {
            steps {
                ... Do something with arg1, arg2 or arg3
            }
        }
        stage('stageB') {
            steps {
                ... Do something with arg1, arg2 or arg3
            }
        }
    ....

I want to centralize the pipeline config so I don't have to worry about Jenkinsfile sprawl. Is this possible with declarative pipelines?

like image 927
red888 Avatar asked Sep 02 '25 18:09

red888


2 Answers

Entire Pipelines can now be defined in shared libraries as of Declarative Pipeline 1.2.

You can find more here and here

like image 118
Chris Mitchell Avatar answered Sep 04 '25 09:09

Chris Mitchell


As the shared libraries plugin documentation states:

Defining Declarative Pipelines

Starting with Declarative 1.2, released in late September, 2017, you can define Declarative Pipelines in your shared libraries as well.

This is fairly new and so there might still be a few bugs around but it should work. Don't forget to upgrade the shared library and declarative plugins though.

like image 28
herm Avatar answered Sep 04 '25 09:09

herm