I'm trying to configure Jenkins as a code, and trying to put pipeline code in configuration. So far I've found in doc (https://github.com/jenkinsci/job-dsl-plugin/tree/master/docs) that I can do it if I pull the script from Git, but since my pipeline is a simple groovy script, I'm trying to figure out how it can be defined in jobs.jcasc.yaml?
My pipeline looks like that:
pipeline {
agent {
kubernetes {
}
}
stages {
stage("test") {
steps {
script {
sshagent (credentials: ['ssh-key']) {
sh "some code"
}
}
}
}
}
}
The only option I've seen is:
- script: |
pipelineJob('name') {
description('build')
definition {
cpsScm {
lightweight(true)
scm {
git {
remote {
url("URL")
credentials("key")
}
branch("master")
}
}
scriptPath("jenkinsfile")
}
}
}