Skip to content

Instantly share code, notes, and snippets.

@robnester-rh robnester-rh/Jenkins Console Output Secret
Last active Apr 23, 2018

Embed
What would you like to do?
def call(Map config, Closure body){
String podName = config.podName ?: "contraDSL-${UUID.randomUUID()}"
String openshiftServiceAccount = config.openshiftServiceAccount ?: 'jenkins'
String openshiftNamespace = config.openshiftNamespace ?: 'contra-dsl'
String dockerRepoURL = config.dockerRepoURL ?: '172.30.1.1:5000'
String ansibleExecutorTag = config.ansibleExecutorTag ?: 'stable'
String linchpinExecutorTag = config.linchpinExecutorTag ?: 'stable'
println(podName)
println(openshiftServiceAccount)
println(openshiftNamespace)
println(dockerRepoURL)
println(ansibleExecutorTag)
println(linchpinExecutorTag)
podTemplate(name: podName,
label: podName,
cloud: 'openshift',
serviceAccount: openshiftServiceAccount,
idleMinutes: 0,
namespace: openshiftNamespace,
containers:[
// This adds the custom slave container to the pod. Must be first with name 'jnlp'
containerTemplate(name: 'jnlp',
image: "${dockerRepoURL}/${openshiftNamespace}/jenkins-contra-slave:stable",
ttyEnabled: false,
args: '${computer.jnlpmac} ${computer.name}',
command: '',
workingDir: '/workDir'),
// This adds the ansible-executor container to the
containerTemplate(name: 'ansible-executor',
image: "${dockerRepoURL}/${openshiftNamespace}/ansible-executor:${ansibleExecutorTag}",
ttyEnabled: true,
command: '',
workingDir: '/ansible'),
// This adds the rpmbuild test container to the pod.
containerTemplate(name: 'linchpin-executor',
alwaysPullImage: true,
image: "${dockerRepoURL}/${openshiftNamespace}/linchpin-executor:${linchpinExecutorTag}",
ttyEnabled: true,
command: '',
workingDir: '/linchpin'),
]
) {
body()
}
}
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Where Am I)
[Pipeline] sh
[foo] Running shell script
+ pwd
/workDir/workspace/foo
[Pipeline] sh
[foo] Running shell script
+ ls -lah
total 24K
drwxr-sr-x. 3 default 1000060000 4.0K Apr 23 19:33 .
drwxr-sr-x. 4 default 1000060000 4.0K Apr 23 19:33 ..
-rw-r--r--. 1 default 1000060000 2.0K Apr 23 19:33 .contra.yml
drwxr-sr-x. 8 default 1000060000 4.0K Apr 23 19:33 .git
-rw-r--r--. 1 default 1000060000 8 Apr 23 19:33 .gitignore
-rw-r--r--. 1 default 1000060000 455 Apr 23 19:33 jenkinsfile
[Pipeline] sh
[foo] Running shell script
+ echo /workDir/workspace/foo
/workDir/workspace/foo
[Pipeline] sh
[foo] Running shell script
+ hostname
contradsl-407aec30-5c57-4f11-81bf-52e014adea12-8f6lg-5xb8x
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Parse Configuration)
[Pipeline] echo
I would parse you!
[Pipeline] echo
java.io.FileNotFoundException: /workDir/workspace/foo/.contra.yml (No such file or directory)
[Pipeline] sh
[foo] Running shell script
+ pwd
/workDir/workspace/foo
[Pipeline] sh
[foo] Running shell script
+ ls -lah
total 24K
drwxr-sr-x. 3 default 1000060000 4.0K Apr 23 19:33 .
drwxr-sr-x. 4 default 1000060000 4.0K Apr 23 19:33 ..
-rw-r--r--. 1 default 1000060000 2.0K Apr 23 19:33 .contra.yml
drwxr-sr-x. 8 default 1000060000 4.0K Apr 23 19:33 .git
-rw-r--r--. 1 default 1000060000 8 Apr 23 19:33 .gitignore
-rw-r--r--. 1 default 1000060000 455 Apr 23 19:33 jenkinsfile
[Pipeline] sh
[foo] Running shell script
+ echo /workDir/workspace/foo
/workDir/workspace/foo
[Pipeline] sh
[foo] Running shell script
+ hostname
contradsl-407aec30-5c57-4f11-81bf-52e014adea12-8f6lg-5xb8x
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
// Create the DSL podTemplate
createDslContainers podName: dslPodName,
dockerRepoURL: dockerRepoURL,
openshiftNamespace: openshiftNamespace,
openshiftServiceAccount: openshiftServiceAccount,
// Pass the remainder of your jenkinsfile as a closure to the createDslContainers method
{
node(dslPodName){
stage("pre-flight"){
deleteDir()
git branch: 'development', url: 'https://github.com/robnester-rh/hdsl_test'
}
stage("Where Am I"){
sh "pwd"
sh "ls -lah"
sh "echo $WORKSPACE"
sh "hostname"
}
stage("Parse Configuration"){
echo 'I would parse you!'
parseConfigYaml()
sh "pwd"
sh "ls -lah"
sh "echo $WORKSPACE"
sh "hostname"
// contai ner('ansible-executor'){
// sh "ls /"
// }
}
}
@Grab('org.yaml:snakeyaml')
import org.yaml.snakeyaml.Yaml
import groovy.json.*
/**
* This method reads a yaml file and parses it to JSON so that it can be
* serialized/deserialized easily and passed around within the pipeline.
*
* @param filename
* @return
*/
def call(String filename=".contra"){
Yaml parser = new Yaml()
try{
env.configJSON = new JsonBuilder(parser.load(("${WORKSPACE}/${filename}.yaml" as File).text))
echo "Found ${filename}.yaml"
} catch ( FileNotFoundException ){
try{
env.configJSON = new JsonBuilder(parser.load(("${WORKSPACE}/${filename}.yml" as File).text))
echo "Found ${filename}.yml"
} catch ( FileNotFoundException e ){
println(e)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.