Jenkins

[Script Console] 실행 중인 job의 파라미터 가져오기

thxxyj 2024. 1. 17. 11:55
728x90

Jenkins Script Console 에서 실행 중인 job의 파라미터 가져오는 방법

def jobname = 'YOUR_JOB_NAME'
def jobinstance = Jenkins.instance.getItemByFullName(jobname)
def startbuildnum = 50000   // build number to start checking
def latestbuild = jobinstance.getLastBuild().toString().split('#')[1].toInteger()

for (int i=startbuildnum; i<=latestbuild; i++){
    def runningbuild = jobinstance.getBuildByNumber(i)
    if (runningbuild.getResult().equals(null)) {   // result == null is running build
      println('buildnumber: ' + i + '->' + runningbuild)
      def params = runningbuild.getAction(hudson.model.ParametersAction).getAllParameters()
      params.each {
        println(it)
   }
    println()  
  }
}


https://stackoverflow.com/questions/40307037/how-to-get-a-list-of-running-jenkins-builds-via-groovy-script
https://stackoverflow.com/questions/60689693/jenkins-groovy-how-to-get-params-global-variable-of-all-running-builds-of-a-gi

https://javadoc.jenkins-ci.org/hudson/model/ParametersAction.html

728x90