
В репозитории, где будут храниться будущие groovy файлы создадим директорию с именем "utilities" и в нем создадим файл "GithubPipeline.groovy" со следующим содержимым:
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()
}
}
}
}
Теперь для создания Item'а достаточно создать в корне репозитория файл с расширением groovy, для того, чтобы на 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)