Jenkins's Itch Scratcher

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 toStringed 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值