Copy Map buildResult = [:]
node( 'controller' ) {
buildResult = build job: '/marslo/artifactory-lib' ,
propagate: true ,
wait: true
buildResult . each { println it }
println """
"result" : ${buildResult.result}
"getBuildVariables()" : ${buildResult.getBuildVariables()}
"getBuildVariables().mytest" : ${buildResult.getBuildVariables().mytest}
"getRawBuild().getEnvVars()" : ${buildResult.getRawBuild().getEnvVars()}
"getRawBuild().getEnvironment()" : ${buildResult.getRawBuild.getEnvironment()}
"getBuildCauses()" : ${buildResult.getBuildCauses()}
"getChangeSets()" : ${buildResult.getChangeSets()}
"buildVariables["mytest"]" : ${buildResult.buildVariables["mytest"]}
"buildResult.rawBuild" : ${buildResult.rawBuild}
"buildResult.rawBuild.log" : ${buildResult.rawBuild.log}
"rawBuild.environment.RUN_CHANGES_DISPLAY_URL" : ${buildResult.rawBuild.environment.RUN_CHANGES_DISPLAY_URL}
"""
} // node
Copy def res = [:]
timestamps { ansiColor( 'xterm' ) {
node( 'controller' ){
cleanWs()
buildResult = build '/marslo/down'
if ( currentBuild . rawBuild . changeSets . isEmpty() ) {
println "no new code committed"
} else {
buildResult . rawBuild . changeSets . each { cs ->
cs . items . each { item ->
println """
-----------------------------
revision : ${item.commitId}
author : ${item.author}
message : ${item.msg}
affected files :
\t\t${item.affectedFiles.collect{ f -> f.editType.name + ' - ' + f.path }.join('\n\t\t\t\t')}
"""
}
}
}
}
}}
Copy if ( manager . build . result . isBetterThan( hudson.model.Result. UNSTABLE) ) {
def cmd = 'ssh -p 29418 $host gerrit review --verified +1 --code --review +2 --submit $GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER'
cmd = manager . build . environment . expand(cmd)
manager . listener . logger . println ( "Merge review: '$cmd'" )
def p = "$cmd" . execute()
manager . listener . logger . println (p .in. text)
manager . addShortText( "M" )
}
Copy currentBuild . displayName = '#' + Integer. toString(currentBuild . number) + ' mytest'
Copy currentBuild . description = 'this is whitebox'
Copy import hudson . AbortException
throw new AbortException ( "throw aborted exception" )
Copy try {
throw new AbortException ( "throw aborted exception" )
} catch (e) {
def sw = new StringWriter ()
e . printStackTrace( new PrintWriter (sw) )
println sw . toString()
// throw e // if not throw error, the catch process will only print the error message
}
Copy import com . cloudbees . plugins . credentials . CredentialsProvider
import com . cloudbees . plugins . credentials . common . StandardCredentials
def sample ( String credential ) {
[
inSSH : { println ".. ${credential}: ssh credential" } ,
inHttps : { println ".. ${credential}: git access token" }
]
}
def runWithCredentials ( String credential ) {
Closure classifyCredential = { cid ->
[
( com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl ) : {
sample( credential ) . inHttps()
} ,
( com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey ) : {
sample( credential ) . inSSH()
}
] . find { it . key . isInstance(cid) } . value . call()
}
classifyCredential CredentialsProvider.lookupCredentials( StandardCredentials.class, jenkins.model.Jenkins.instance ).find { credential == it.id }
}
[ 'GITHUB_ACCESS_TOKEN' , 'GITHUB_SSH_CREDENTIAL' ] . each { runWithCredentials(it) }