1 If we set job properties in the Pipeline script, the user SYSTEM on Jenkins will reconfigure the job
That will override our existing configuration. So we set property in .jsonnet
2 If we leave some un-serializable data, that’s fine. But if we try to some stage upon it, that won’t work.
Jenkins try serializing data in some critical points. For example
def nums = [1, 2, 3]
for (int num : nums) {
build job ... // java.io.NotSerializableException: java.util.AbstractList$Itr
}
// To solve it, use C-style loops instead of iterator
For another example,
for (LazyMap x : list) {
if () {
stage() {
//
}
}
}
3 No positional parameter
def f(int x, boolean y = true) {
println(x)
println(y)
}
f(1, false,)
f(2, y=false,) // wrong, (int, null) in Jenkins pipeline
4 Parameter passing
array is serializable, but can’t be passed as parameter
For example,
No signature of methods applicable for argument types: (java.lang.String, [Ljava.lang.String;) values: [x, [y, z]]
is caused when
def f(String x, String[] arr)
is called
But def f(String x, java.util.ArrayList list)
works when we pass a list.
It is deducted that actual parameters will be toString
ed and then deserialized, finally passed to formal parameter.
5 Load groovy source file
load: Evaluate a Groovy source file into the Pipeline script
so Groovy source file is like
class X implements java.io.Serializable {
def steps
X(steps) {
this.steps = steps
}
}
{ steps ->
new X(steps)
}
pipeline script can be
node('jenkins-master-executor') {
// Use a random name for the groovy script to get around caching issues in Jenkins Pipelines
def localPath = "library-" + Math.abs((new java.util.Random()).nextLong()).toString()
downloadFileFromGit(repoPath, localPath)
load "${pwd()}/$localPath"
}
6 node(), ws(), dir()
node: alloc a new executor
ws: alloc a new workspace, i.e. an isolated location on the filesystem
dir: a new location on the filesystem