簡體   English   中英

groovy 語法將 null 作為 null object 返回,而不是 Jenkins 管道中的字符串

[英]What will be the groovy syntax to return null as a null object not a string in Jenkins pipeline

BRANCH = "develop" 

BRANCH = "${BRANCH=="develop"?"null":"${BRANCH}"}"

print (BRANCH.getClass()) # class org.codehaus.groovy.runtime.GStringImpl

將 null 視為 NUllObject 的正確語法是什么? 期望返回 class org.codehaus.groovy.runtime.NullObject

您的三進制當前返回一個包含字符null的字符串,因此您需要修改為:

BRANCH = BRANCH == 'develop' ? null : BRANCH

作為實際作為管道運行的一個非常小的例子,你可以使用這個:

pipeline {
  agent any

  stages {
    stage('Hello') {
      steps {
        script {
          def BRANCH = "develop" 
          BRANCH = "${BRANCH}" == "develop" ? null : "${BRANCH}"
          print (BRANCH.getClass())
        }
      }
    }
  }
}

output 看起來像這樣: 控制台輸出

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM