Jenkins – DSL Pipeline creating by Seed Job

In the repository where the future groovy files will be stored, create a directory called “utilities” and create the file “GithubPipeline.groovy” in it with the following contents:

package utilities

import javaposse.jobdsl.dsl.DslFactory

class GithubPipeline {

    String name
    String description
    String displayName
    String branchesName
    String urlRepo
    String credentialsId


	void build(DslFactory dslFactory) {
	    def job = dslFactory.pipelineJob(name) {
	        description(description)
	        displayName(displayName)
			definition {
		        cpsScm {
		            scm {
		                git {
		                    branches(branchesName)
		                    remote {
		                        url(urlRepo)
                        		credentials(credentialsId)
		                    }
		                }
		                scriptPath('Jenkinsfile')
		                lightweight(true)
		            }
		        }
		    }
		    parameters {
		        choiceParam ('Environment', ['staging', 'production', 'staging-without-cache'], 'Please choice env to build')
		    }
		    triggers {
		        bitbucketPush()
		    }
		}
	}
}

Now, to create an Item, it is enough to create a file with the groovy extension in the root of the repository, so that it can be processed by Seed Job.

pipeline-dsl.groovy

import utilities.GithubPipeline

def pipeline = new GithubPipeline(
    description: 'Pipeline DSL',
    name: 'pipeline-dsl',
    displayName: 'Pipeline DSL',
    branchesName: '*/pipeline-dsl',
    urlRepo: '[email protected]:artem/devops.git',
    credentialsId: 'artem-github'
).build(this)

Tagged: Tags

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Vivek Mishra
Vivek Mishra
4 years ago

Hi,
Based on your example mentioned above with seed job. I am facing the error “Unable to load class import utilities.GithubPipeline”
Job DSL pluging 1.67

Any suggestions.
Many thanks,
Vivek