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)
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
Hi!
I think this is a security issue. Try to disable "Script Security", this is not a good solution, but if it helps, you at least will know the reason
I hope it helps to you following URL:
https://github.com/jenkinsci/job-dsl-plugin/wiki/Script-Security