Skip to content

Commit de6c244

Browse files
committed
Adding an example of a global function.
1 parent 42370e3 commit de6c244

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!groovy
2+
3+
// Loads the standardBuild method from workflowLibs.git/vars/standardBuild.groovy
4+
// and invokes it.
5+
standardBuild {
6+
environment = 'golang:1.5.0'
7+
mainScript = '''
8+
go version
9+
go build -v hello-world.go
10+
'''
11+
postScript = '''
12+
ls -l
13+
./hello-world
14+
'''
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Synopsis
2+
An example of how to define a global function for the Workflow DSL on
3+
your Jenkins master using the global CPS library.
4+
5+
# Credit
6+
7+
This comes from the [CloudBeers demo](https://github.com/cloudbeers/multibranch-demo).
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// See https://github.com/jenkinsci/workflow-plugin/tree/master/cps-global-lib#defining-global-functions
2+
3+
// The call(body) method in any file in workflowLibs.git/vars is exposed as a
4+
// method with the same name as the file.
5+
def call(body) {
6+
def config = [:]
7+
body.resolveStrategy = Closure.DELEGATE_FIRST
8+
body.delegate = config
9+
body()
10+
stage 'checkout'
11+
node {
12+
checkout scm
13+
stage 'main'
14+
docker.image(config.environment).inside {
15+
sh config.mainScript
16+
}
17+
stage 'post'
18+
sh config.postScript
19+
}
20+
}

0 commit comments

Comments
 (0)