Accessing the current Jenkins build in Groovy script

后端 未结 3 1994
攒了一身酷
攒了一身酷 2021-02-14 06:09

I have created a Groovy script which is used in a System Groovy Script step in a Jenkins job which needs to access the current build of the current job.

T

3条回答
  •  执笔经年
    2021-02-14 06:44

    This completes the answer from luka5z to exemplify how scriptler passes the listener to the groovy script:

    import jenkins.model.*;
    import hudson.model.*;
    import hudson.util.*;
    import hudson.tasks.*;
    import hudson.plugins.git.*;
    import hudson.scm.*
    import jenkins.scm.*
    
    def build = Thread.currentThread()?.executable
    //def svn_branch = build.buildVariableResolver.resolve("SVN_BRANCH")
    
    if (build instanceof AbstractBuild){
        def workspace = build.workspace
        //def job = build.parent
        def scm = build.parent.scm;
        //println "scm: $scm"
    
        if (scm instanceof hudson.scm.SubversionSCM) {
            scm.checkout(build, null/*Launcher*/, workspace /*workspace*/, listener/*listener*/, null /*changelogfile*/,null/*baseline*/)
        }else if (scm instanceof hudson.plugins.git.GitSCM) {
            scm.checkout(build, null/*Launcher*/, workspace /*workspace*/, listener/*listener*/, null /*changelogfile*/,null/*baseline*/)
        }
    }
    

    listener in Scriptler

提交回复
热议问题