Skip to main content

Groovy script examples

 

trigger a job 
PurposeScript
Reflection
activeJobs = hudson.model.Hudson.instance.items.findAll{job -> job.isBuildable()}

for (j in activeJobs)
{
 describe (j.asProject().getLastBuild())
}



def describe (o)
{
 println (o.toString() + " ("+o.getClass()+")")
 
 println ("\tList of fields")
 for( field in o.getClass().getFields() )
 {
  println "\t\t"+field.getType().getName() + "\t"+field.getName() + "\t("+field.get(o)+")"
 }
 
 println ("\tList of methods")
 for( method in o.getClass().getMethods() )
 {
  result = "("+method.getParameterTypes().length+" args)"
  if (method.getParameterTypes().length == 0)
  {
   if ((method.toString().indexOf("java.lang.Object")==-1) && (method.toString().indexOf(".get")==-1))
    result = method.invoke(o)
   else
    result = "java lang method"
  }
  println "\t\t"+method.toString() + "\t"+result
 }
 println "***END***"
}
Delete workspace
deleteWorkspaceIfNotRunning ("ApolloQAP_FindBugs")

def deleteWorkspaceIfNotRunning (jobName)
{
job = hudson.model.Hudson.instance.items.find{job -> job.name == jobName}
println ("Delete workspace for "+job.getName() + " if not under progress")

if (!job.isBuilding())
{
println (" >>> Delete workspace for "+job.getName() + " ...")
job.doDoWipeOutWorkspace()
}
else
{
println (" >>> Do not delete workspace for "+job.getName() + " because it is currently under progress")
}
}

trigger job if given job failed
urJobName = "Staging_ForZiv_triggerSironInCaseOfFailure"
triggeredJobName = "InvokeKitchenSiron"


job = hudson.model.Hudson.instance.items.find{job -> job.name == curJobName}
run = job.getLastBuild()
println (job.name + " last build is " + run.number + " with status " + run.result)


if (run.result == run.result.FAILURE) 
{
  println ("Job failed so trigger " + triggeredJobName)
  triggeredJob = hudson.model.Hudson.instance.items.find{job -> job.name == "InvokeKitchenSiron"}
//  triggeredJob.newBuild()
}
else
{
  println ("Job passed")
}

job = hudson.model.Hudson.instance.items.find{job -> job.name == "name"}
job.newBuild()

Comments

לדעתי צריך להוסיף שברגע שאתה חחונה אפשר לבקש מחובש לרדת לכוון אותך אם יש צורך

Popular posts from this blog

Jenkins error: groovy.lang.MissingPropertyException

I tried to run groovy build step and got below error. This post will describe how I solved the problem.

Caught: groovy.lang.MissingPropertyException: No such property: hudson for class: script


What is PKI

PKI = Public Key Infrastructure
(Resource) Method of asserting the identity and validity of a person (or entity) that you have not previously met or interacted.

It use of certificates containing identifying information and public keys (these certificates are more properly called X.509 certificates).

PKI accomplishes this by defining a central authority who is mutually trusted by all users of the system.