From a3fa178233e3e0def87436cadc4a2733398fd2f8 Mon Sep 17 00:00:00 2001 From: "Rafael M. Pestano" Date: Thu, 11 Jan 2018 08:44:00 -0200 Subject: [PATCH] Update README.adoc Adds docs about scripting in pipeline --- README.adoc | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 92c5cbd..1b411d1 100644 --- a/README.adoc +++ b/README.adoc @@ -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: @@ -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 <>. 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