Article From:https://www.cnblogs.com/sunada2005/p/9121977.html

Jenkins is often used in continuous integration. There are many plug-ins on the Jenkins. Using these plug-ins can help us improve efficiency.

1. groovy postbuild Get construction related data

groovyIt’s a programming language. We can write groovy scripts to get some data in construction, such as building numbers, branch, etc. In the “increase structure operation steps”, select the goovy postbuild tool. You can use the following code to get people to build, build branches, etc.Interest.

def user = manager.build.getCause(hudson.model.Cause.UserIdCause.class).getUserName()
def matcher = manager.getLogMatcher(".*-(.*-.*).ipa")
if(matcher?.matches()) {
  manager.addShortText("${matcher.group(1)}@${user}")
}

def  branch = manager.build.getBuildVariables().get("BRANCH")
def  slave = manager.build.getBuiltOnStr()
desc = "Br: ${branch} Sl: ${slave}"
desc = "Br: ${branch}"
Thread.currentThread().executable.setDescription(desc)

  In the script, get the build information from the build log and get the branch information from the parameter. When executing, you may encounter problems without permission, such as

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method hudson.model.Run setDescription java.lang.String
at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:160)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:119)
In this case, you need 1. not to select Use Groovy Sandbox 2. and then find Jenkins's adminstor to navigate to jenkins> manage jenkins> the script approval within the process agrees that this script will notThis is the problem.

 

Similar Posts:

Link of this Article: Jenkins continuous integration

Leave a Reply

Your email address will not be published. Required fields are marked *