Hello all,
I have a question centered around using the "task" method in a script block in a declarative Jenkinsfile. What I'm attempting to do is create a DSL using Groovy where the Jenkinsfile is essentially a config file allowing a dev team to fill in string values and have the declarative pipeline build their projects behind the scenes.
Here's an example Jenkinsfile:
// Jenkinsfile
@Library('pipeline-library') _
project {
commit {
buildScript 'build.ps1'
}
}
vars/project.groovy in the shared 'pipeline-library' would look like this:
// vars/project.groovy
import groovy.transform.Field
import com.foo.*
@Field Closure commitClosure
def call(body) {
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = this
pipeline {
agent any
stages {
stage('Commit') {
steps {
script {
commitClosure()
}
}
}
}
}
}
def commit(Closure cl) {
cl.resolveStrategy = Closure.DELEGATE_FIRST
cl.delegate = commit
commitClosure = cl
}
and vars/commit.groovy would be:
// vars/commit.groovy
def call(body) {
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = this
body()
}
def buildScript(String str) {
task 'Compile'
powershell str
}
However, since the commit closure is executed in the script block, the task is not showing up in the stage in the Delivery Pipeline view.
First, is there a better way I should be creating the DSL, and second, is it intended that tasks not show up in the stage view when executed from a script block?
Thanks in advanced!
Joseph