forked from jenkinsci/JenkinsPipelineUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for global vars and steps
- Loading branch information
1 parent
a317fb5
commit b196fcf
Showing
12 changed files
with
157 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/groovy/com/lesfurets/jenkins/unit/global/lib/LibraryConfiguration.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/groovy/com/lesfurets/jenkins/unit/global/lib/LibraryCpsTransformer.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.lesfurets.jenkins.unit.global.lib | ||
|
||
import org.codehaus.groovy.ast.ClassNode | ||
import org.codehaus.groovy.ast.MethodNode | ||
import org.codehaus.groovy.classgen.GeneratorContext | ||
import org.codehaus.groovy.control.SourceUnit | ||
|
||
import com.cloudbees.groovy.cps.CpsTransformer | ||
|
||
class LibraryCpsTransformer extends CpsTransformer { | ||
|
||
boolean skipTransform = false | ||
|
||
@Override | ||
void call(SourceUnit source, GeneratorContext context, ClassNode classNode) { | ||
boolean f = source.name.contains('/vars/') | ||
skipTransform = f | ||
super.call(source, context, classNode) | ||
skipTransform = false | ||
} | ||
|
||
@Override | ||
protected boolean shouldBeTransformed(MethodNode node) { | ||
return !skipTransform && super.shouldBeTransformed(node) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/groovy/com/lesfurets/jenkins/unit/global/lib/LibraryRecord.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.lesfurets.jenkins.unit.global.lib | ||
|
||
import groovy.transform.Canonical | ||
|
||
@Canonical | ||
class LibraryRecord { | ||
|
||
LibraryConfiguration configuration | ||
String version | ||
Map<String, Object> definedGlobalVars | ||
|
||
String getIdentifier() { | ||
return "$configuration.name@$version" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/test/resources/shared-scripts/commons@master/vars/acme.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// vars/acme.groovy | ||
class acme implements Serializable { | ||
private String name = "something" | ||
def setName(value) { | ||
name = value | ||
} | ||
def getName() { | ||
name | ||
} | ||
def caution(message) { | ||
echo "Hello, ${name}! CAUTION: ${message}" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/test/resources/shared-scripts/commons@master/vars/sayHello.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// vars/sayHello.groovy | ||
def call(String name = 'human') { | ||
// Any valid steps can be called from this code, just like in other | ||
// Scripted Pipeline | ||
echo "Hello, ${name}." | ||
} |