在Jenkinsfile中运行kubectl cmd

时间:2019-05-23 23:38:23

标签: jenkins-pipeline kubectl

我想运行Jenkinsfile并执行kubectl命令。 我能够手动运行kubectl命令并能够部署到eks 但我想让它自动化,这是我的Jenkinsfile

node('docker-host') {

  def k8sImage = docker.image('roffe/kubectl:latest')
  stage('Create Env') {
    print('inside k8 env')  
  }
   stage('Update IRIS dev') {
        k8sImage.inside {

            sh "kubectl get all"

        }
      }

}

这是我的console.log文件。我已将其范围缩小到与AWS IAM Authenticator有关

https://github.com/kubernetes-sigs/aws-iam-authenticator

[kubectl_test] Running shell script
+ docker inspect -f . roffe/kubectl:latest
.
[Pipeline] withDockerContainer

$ docker run -t -d -u 0:0 -w /var/lib/jenkins-slave/workspace/ow/ow_eng/kubectl_test -v /var/lib/jenkins-slave/workspace/ow/ow_eng/kubectl_test:/var/lib/jenkins-slave/workspace/ow/ow_eng/kubectl_test:rw,z -v /var/lib/jenkins-slave/workspace/ow/ow_eng/kubectl_test@tmp:/var/lib/jenkins-slave/workspace/ow/ow_eng/kubectl_test@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat roffe/kubectl:latest
[Pipeline] {
[Pipeline] sh
[kubectl_test] Running shell script
+ kubectl config '--kubeconfig=config-demo' set-cluster scratch '--server=https://123456789.yl4.us-west-2.eks.amazonaws.com' --insecure-skip-tls-verify
Cluster "scratch" set.
[Pipeline] sh
[kubectl_test] Running shell script
+ kubectl config '--kubeconfig=config-demo' set-context exp-scratch '--cluster=scratch' '--namespace=ow-frontend' '--user=experimenter'
Context "exp-scratch" modified.
[Pipeline] sh
[kubectl_test] Running shell script
+ kubectl config '--kubeconfig=config-demo' set-credentials experimenter '--username=exp' '--password=some-password'
User "experimenter" set.
[Pipeline] sh
[kubectl_test] Running shell script
+ kubectl config '--kubeconfig=config-demo' use-context exp-scratch
Switched to context "exp-scratch".
[Pipeline] sh
[kubectl_test] Running shell script
+ kubectl config view '--kubeconfig=config-demo'
apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://123456789.yl4.us-west-2.eks.amazonaws.com
  name: scratch
contexts:
- context:
    cluster: scratch
    namespace: ow-frontend
    user: experimenter
  name: exp-scratch
current-context: exp-scratch
kind: Config
preferences: {}
users:
- name: experimenter
  user:
    password: some-password
    username: exp
[Pipeline] sh
[kubectl_test] Running shell script
+ kubectl get pods '--kubeconfig=config-demo'
No resources found.
Error from server (Forbidden): pods is forbidden: User "system:anonymous" cannot list resource "pods" in API group "" in the namespace "ow-frontend"
[Pipeline] }
$ docker stop --time=1 e6eea3125f5d99bd797452886ff240599a850169489e969ba73667efd9cfbc1e
$ docker rm -f e6eea3125f5d99bd797452886ff240599a850169489e969ba73667efd9cfbc1e
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

0 个答案:

没有答案