Created
August 4, 2017 16:00
-
-
Save austinmoore-/b26b61d65072400b64ec205ba31628cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A job that just sleeps. | |
* | |
* PARAMETERS or global variables. | |
* - k8sClusterName (global): The cluster name | |
* - k8sPodNamePrefix: The pod name's prefix | |
* - awsIamRole: The IAM role the pod will use | |
* - dockerRegistry (global): The Docker registry our Docker images are in | |
* - kubectlTag (global): The kubectl Docker image tag | |
* - jnlpTag (global): The JNLP agent Docker image tag | |
*/ | |
import java.util.Random | |
Random random = new Random() | |
node('master') { | |
podLabel = JOB_BASE_NAME + random.nextInt(100000) | |
podName = k8sPodNamePrefix | |
clusterName = k8sClusterName | |
registry = dockerRegistry | |
jnlpTag = jnlpContainerTag | |
kubectlTag = kubectlContainerTag | |
k8sCredentials = '/var/secrets/jenkins-k8s-credentials' | |
} | |
podTemplate( | |
cloud: clusterName, | |
name: podName, | |
label: podLabel, | |
nodeUsageMode: 'EXCLUSIVE', | |
serviceAccount: "jenkins", | |
containers: [ | |
containerTemplate( | |
name: 'busybox', | |
image: "busybox", | |
ttyEnabled: true, | |
command: 'cat' | |
), | |
containerTemplate( | |
name: 'jnlp', | |
image: "${registry}/jnlp-agent:${jnlpTag}", | |
args: '${computer.jnlpmac} ${computer.name}', | |
ttyEnabled: true | |
) | |
], | |
volumes: [ | |
secretVolume( | |
mountPath: k8sCredentials, | |
secretName: 'jenkins-k8s-credentials'), | |
configMapVolume( | |
mountPath: '/etc/ssl/jenkins/', | |
configMapName: 'jenkins-cert' | |
) | |
]) { | |
node(podLabel) { | |
stage('Sleep') { | |
container('jnlp') { | |
hostname = | |
sh( | |
returnStdout: true, | |
script: "wget -q ${hostNameUrl} -O -" | |
).trim() | |
echo "AWS Instance: ${hostname}" | |
sh 'echo "Pod Name: `hostname`"' | |
} | |
container('busybox') { | |
sh 'sleep 300' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment