Jenkins GroovyCodeLink trimmed according to my requirement我一直在尝试获取Jenkins本身提供的以下jenkins Groovy代码的UserID和时间戳/日期,我尝试添加不同的参数来获取特定构建的userid和时间戳/日期。由常规代码拉出。感谢有人请帮助我:
我期望生成的开始日期和人类可读的时间戳,例如mm / dd / yyyy以及时间和用户ID。
import hudson.model.FreeStyleBuild
import hudson.model.Job
import hudson.model.Result
import hudson.model.Run
import java.util.Calendar
import jenkins.model.Jenkins
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.jenkinsci.plugins.workflow.support.steps.StageStepExecution
//24 hours in a day, 3600 seconds in 1 hour, 1000 milliseconds in 1 second
long time_in_millis = 24*3600*1000
Calendar rightNow = Calendar.getInstance()
Jenkins.instance.getAllItems(Job.class).findAll { Job job ->
job.isBuilding()
}.collect { Job job ->
//find all matching items and return a list but if null then return an empty list
job.builds.findAll { Run run ->
run.isBuilding() && ((rightNow.getTimeInMillis() - run.getStartTimeInMillis()) > time_in_millis)
} ?: []
}.sum().each { Run item ->
if(item in WorkflowRun) {
WorkflowRun run = (WorkflowRun) item
//release pipeline concurrency locks
StageStepExecution.exit(run)
println "JOBS: ${run}"
} else if(item in FreeStyleBuild) {
FreeStyleBuild run = (FreeStyleBuild) item
println "JOBS: ${run}"
} else {
println "WARNING: Don't know how to handle ${item.class}"
}
}
//null means there will be no return result for the script
null