Skip to content

Instantly share code, notes, and snippets.

@rabun788
Last active October 17, 2019 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rabun788/9cd5bf2ad0301042d52907b566167c14 to your computer and use it in GitHub Desktop.
Save rabun788/9cd5bf2ad0301042d52907b566167c14 to your computer and use it in GitHub Desktop.
Started by user admin
Obtained google-cloud/googleproject/buckets/ci/Jenkinsfile from git https://source.developers.google.com/p/googleproject/r/blah-cloud-deploy
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] readTrusted
Obtained google-cloud/googleproject/jenkins/KubernetesPod.yaml from git https://source.developers.google.com/p/googleproject/r/blah-cloud-deploy
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
‘blah-cloud-deploy-jenkins-agent-cs43m-ctp13’ is offline
Agent blah-cloud-deploy-jenkins-agent-cs43m-ctp13 is provisioned from template Kubernetes Pod Template
---
apiVersion: "v1"
kind: "Pod"
metadata:
annotations:
buildUrl: "http://cd-jenkins:8080/job/googleproject-buckets/17/"
labels:
blah: "build"
jenkins: "slave"
jenkins/blah-cloud-deploy-jenkins-agent: "true"
name: "blah-cloud-deploy-jenkins-agent-cs43m-ctp13"
spec:
containers:
- env:
- name: "blah"
value: "build"
image: "gcr.io/googleproject/blah-cloud-deploy-jenkins-agent"
name: "blah"
tty: true
volumeMounts:
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
- env:
- name: "JENKINS_SECRET"
value: "********"
- name: "JENKINS_TUNNEL"
value: "cd-jenkins-agent:50000"
- name: "JENKINS_AGENT_NAME"
value: "blah-cloud-deploy-jenkins-agent-cs43m-ctp13"
- name: "JENKINS_NAME"
value: "blah-cloud-deploy-jenkins-agent-cs43m-ctp13"
- name: "JENKINS_AGENT_WORKDIR"
value: "/home/jenkins/agent"
- name: "CONTAINER_ENV_VAR"
value: "jnlp"
- name: "JENKINS_URL"
value: "http://cd-jenkins:8080/"
image: "jenkins/jnlp-slave:alpine"
name: "jnlp"
volumeMounts:
- mountPath: "/home/jenkins/agent"
name: "workspace-volume"
readOnly: false
nodeSelector: {}
restartPolicy: "Never"
volumes:
- emptyDir: {}
name: "workspace-volume"
Running on blah-cloud-deploy-jenkins-agent-cs43m-ctp13 in /home/jenkins/agent/workspace/googleproject-buckets
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
java.lang.IllegalStateException: Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong.
at jenkins.model.Jenkins.get(Jenkins.java:772)
at hudson.model.Hudson.getInstance(Hudson.java:77)
at com.google.jenkins.plugins.source.GoogleRobotUsernamePassword.areOnMaster(GoogleRobotUsernamePassword.java:146)
at com.google.jenkins.plugins.source.GoogleRobotUsernamePassword.readObject(GoogleRobotUsernamePassword.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1170)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2178)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2069)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1975)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1567)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2287)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2211)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2069)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1573)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
at hudson.remoting.UserRequest.deserialize(UserRequest.java:290)
at hudson.remoting.UserRequest.perform(UserRequest.java:189)
Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 10.0.0.26/10.0.0.26:58226
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1743)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
at hudson.remoting.Channel.call(Channel.java:957)
at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:283)
at com.sun.proxy.$Proxy86.addCredentials(Unknown Source)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl.addCredentials(RemoteGitImpl.java:200)
at hudson.plugins.git.GitSCM.createClient(GitSCM.java:845)
at hudson.plugins.git.GitSCM.createClient(GitSCM.java:813)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:124)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
Caused: java.lang.Error: Failed to deserialize the Callable object.
at hudson.remoting.UserRequest.perform(UserRequest.java:195)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:97)
Caused: java.io.IOException: Remote call on JNLP4-connect connection from 10.0.0.26/10.0.0.26:58226 failed
at hudson.remoting.Channel.call(Channel.java:963)
at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:283)
Caused: hudson.remoting.RemotingSystemException
at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:299)
at com.sun.proxy.$Proxy86.addCredentials(Unknown Source)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl.addCredentials(RemoteGitImpl.java:200)
at hudson.plugins.git.GitSCM.createClient(GitSCM.java:845)
at hudson.plugins.git.GitSCM.createClient(GitSCM.java:813)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:124)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
pipeline {
environment {
GOOGLE_PROJECT='blah'
PIPELINE_DIR="google-cloud/$GOOGLE_PROJECT/buckets"
CLOUDSDK_CORE_DISABLE_PROMPTS='true'
HOME="$WORKSPACE" //important to set this variable to that gcloud and gsutil will work properly
TERRAFORM_CREDENTIALS="terraform-${GOOGLE_PROJECT}"
}
agent {
kubernetes {
label 'blah-project-jenkins-agent'
defaultContainer 'siphon'
yamlFile 'google-cloud/blah/jenkins/KubernetesPod.yaml'
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '3'))
disableConcurrentBuilds()
timeout(time: 24, unit: 'HOURS')
}
stages {
stage('terragen') {
environment {
GOOGLE_APPLICATION_CREDENTIALS = credentials("$env.TERRAFORM_CREDENTIALS")
}
steps {
dir("$env.PIPELINE_DIR/..") {
sh '''
#!/usr/bin/env bash -e -x
./script/terragen
'''
}
}
}
stage('terraform setup') {
environment {
GOOGLE_APPLICATION_CREDENTIALS = credentials("$env.TERRAFORM_CREDENTIALS")
}
steps {
dir("$env.PIPELINE_DIR") {
sh '''
#!/usr/bin/env bash -e -x
./script/terraform setup
'''
}
}
}
stage('terraform plan') {
environment {
GOOGLE_APPLICATION_CREDENTIALS = credentials("$env.TERRAFORM_CREDENTIALS")
}
steps {
dir("$env.PIPELINE_DIR") {
sh '''
#!/usr/bin/env bash -e -x
./script/terraform plan
'''
}
}
}
stage('verify plan') {
steps {
dir("$env.PIPELINE_DIR") {
script {
env.PLAN_URI = 'gs://' + env.GOOGLE_PROJECT + '-jenkins-artifacts/' +
env.JOB_NAME + '/' + env.BUILD_NUMBER + '/plan.txt'
}
googleStorageDownload \
credentialsId: env.GOOGLE_PROJECT,
bucketUri: env.PLAN_URI,
localDirectory: '.'
script {
String fileContents = readFile(env.JOB_NAME + '/' + env.BUILD_NUMBER + '/plan.txt')
TERRAFORM_PLAN_HAS_CHANGES = true
if (fileContents.indexOf("No changes. Infrastructure is up-to-date.") > 0) {
echo "No changes!"
TERRAFORM_PLAN_HAS_CHANGES = false
}
}
}
}
}
stage('approval') {
when {
expression { TERRAFORM_PLAN_HAS_CHANGES != false }
}
steps {
timeout (time: 1, unit:'DAYS'){
script {
def message = 'Apply Terraform Plan?\n\nhttps://storage.cloud.google.com/' +
env.GOOGLE_PROJECT + '-jenkins-artifacts/' +
env.JOB_NAME + '/' + env.BUILD_NUMBER + '/plan.txt'
def userInput = input(message: message)
}
}
}
}
stage('terraform apply') {
when {
expression { TERRAFORM_PLAN_HAS_CHANGES != false }
}
environment {
GOOGLE_APPLICATION_CREDENTIALS = credentials("$env.TERRAFORM_CREDENTIALS")
}
steps {
dir("$env.PIPELINE_DIR") {
sh '''
#!/usr/bin/env bash -e -x
./script/terraform apply
'''
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment