Skip to content

Commit

Permalink
Update README.adoc
Browse files Browse the repository at this point in the history
Adds docs about scripting in pipeline
  • Loading branch information
rmpestano committed Jan 11, 2018
1 parent 58d03f8 commit a3fa178
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.adoc
Expand Up @@ -123,7 +123,7 @@ node {
----


=== Pipeline script DSL
=== Pipeline DSL

Since version `1.0.10` it is possible to use the _lastChanges()_ shortcut in pipeline DSL:

Expand Down Expand Up @@ -177,6 +177,37 @@ pipeline {

TIP: Refer to https://wiki.jenkins.io/display/JENKINS/Parameterized+Build[parameterized builds^] to use parameters.

=== Pipeline scripting

Since https://github.com/jenkinsci/last-changes-plugin/releases/tag/2.5[v2.5^] is possible to invoke LastChanges inside groovy script, instead of just declaring it <<Pipeline DSL, as we saw above>>. See example below:

```
node {
stage("checkout") {
git url: 'https://github.com/jenkinsci/last-changes-plugin.git'
}

stage("last-changes") {
def publisher = LastChanges.getLastChangesPublisher "PREVIOUS_REVISION", "SIDE", "LINE", true, true, "", "", "", "", ""
publisher.publishLastChanges()
def changes = publisher.getLastChanges()
println(changes.getEscapedDiff())
for (commit in changes.getCommits()) {
println(commit)
def commitInfo = commit.getCommitInfo()
println(commitInfo)
println(commitInfo.getCommitMessage())
println(commit.getChanges())
}
}

}
```

NOTE: See https://github.com/jenkinsci/last-changes-plugin/blob/master/src/main/java/com/github/jenkins/lastchanges/model[model classes^] to know what can be accessed in pipeline script. Note that only attributes https://github.com/jenkinsci/last-changes-plugin/blob/master/src/main/java/com/github/jenkins/lastchanges/model/LastChanges.java#L48[annotated with @Whitelisted^] are visible to be accessed in pipeline script.

TIP: If you use declarative pipeline you can use https://jenkins.io/doc/book/pipeline/syntax/#script[script section^].


== Docker

Expand Down

0 comments on commit a3fa178

Please sign in to comment.