docker - Jenkinsfile docker

标签 docker jenkins google-cloud-platform kubernetes jenkins-pipeline

我正在Docker容器内的GCE上运行jenkins实例,并希望从此Jenkinsfile和Github执行多分支管道。我正在为此使用GCE jenkins教程。这是我的Jenkinsfile

node {
  def project = 'xxxxxx'
  def appName = 'gceme'
  def feSvcName = "${appName}-frontend"
  def imageTag = "eu.gcr.io/${project}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}"

  checkout scm

  sh("echo Build image")
  stage 'Build image'
  sh("docker build -t ${imageTag} .")

  sh("echo Run Go tests")
  stage 'Run Go tests'
  sh("docker run ${imageTag} go test")

  sh("echo Push image to registry")
  stage 'Push image to registry'
  sh("gcloud docker push ${imageTag}")

  sh("echo Deploy Application")
  stage "Deploy Application"
  switch (env.BRANCH_NAME) {
    // Roll out to canary environment
    case "canary":
        // Change deployed image in canary to the one we just built
        sh("sed -i.bak 's#eu.gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/canary/*.yaml")
        sh("kubectl --namespace=production apply -f k8s/services/")
        sh("kubectl --namespace=production apply -f k8s/canary/")
        sh("echo http://`kubectl --namespace=production get service/${feSvcName} --output=json | jq -r '.status.loadBalancer.ingress[0].ip'` > ${feSvcName}")
        break

    // Roll out to production
    case "master":
        // Change deployed image in canary to the one we just built
        sh("sed -i.bak 's#eu.gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/production/*.yaml")
        sh("kubectl --namespace=production apply -f k8s/services/")
        sh("kubectl --namespace=production apply -f k8s/production/")
        sh("echo http://`kubectl --namespace=production get service/${feSvcName} --output=json | jq -r '.status.loadBalancer.ingress[0].ip'` > ${feSvcName}")
        break

    // Roll out a dev environment
    default:
        // Create namespace if it doesn't exist
        sh("kubectl get ns ${env.BRANCH_NAME} || kubectl create ns ${env.BRANCH_NAME}")
        // Don't use public load balancing for development branches
        sh("sed -i.bak 's#LoadBalancer#ClusterIP#' ./k8s/services/frontend.yaml")
        sh("sed -i.bak 's#eu.gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/dev/*.yaml")
        sh("kubectl --namespace=${env.BRANCH_NAME} apply -f k8s/services/")
        sh("kubectl --namespace=${env.BRANCH_NAME} apply -f k8s/dev/")
        echo 'To access your environment run `kubectl proxy`'
        echo "Then access your service via http://localhost:8001/api/v1/proxy/namespaces/${env.BRANCH_NAME}/services/${feSvcName}:80/"
  }
}

我总是收到错误docker not found:
[apiservice_master-GJCRJX6ZJPDVVSEUHIS6VBX7OYMFS5WKRVRKCSF4PSO76ZGZPKFQ] Running shell script
+ docker build -t eu.gcr.io/xxxxx/apiservice:master.1 .
/var/jenkins_home/workspace/apiservice_master-GJCRJX6ZJPDVVSEUHIS6VBX7OYMFS5WKRVRKCSF4PSO76ZGZPKFQ@tmp/durable-b4503ecc/script.sh: 2: /var/jenkins_home/workspace/apiservice_master-GJCRJX6ZJPDVVSEUHIS6VBX7OYMFS5WKRVRKCSF4PSO76ZGZPKFQ@tmp/durable-b4503ecc/script.sh: docker: not found

为了使docker在jenkins中工作,我必须更改什么?

最佳答案

看起来像DiD(Docker中的Docker),此recent issue指出这是有问题的。
参见“Using Docker-in-Docker for your CI or testing environment? Think twice.

相同的问题建议以特权模式运行。
并确保您要在其中执行的Docker容器安装了docker。

关于docker - Jenkinsfile docker ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43958052/

相关文章:

docker - Docker Compose按需激活容器

docker - Azure devops发布管道-在环境之间共享的特定docker镜像

java - 从 ANT 运行 junitreport 时出现 OutOfMemoryError

apache - 两种服务 HTTP 谷歌计算引擎

java - 无法在 Android 中导入 com.google.cloud.speech.v1.SpeechGrpc

docker - 多阶段docker镜像是否具有相同的层?

docker - 共享 Maven 存储库的共享数据量

jenkins - 使用环境变量 Jenkins Pipeline 加载文件

jenkins - 在 Jenkins 中设置 24 小时时钟格式

sql-server - 远程连接到在 Google Cloud 虚拟机上运行的 SQL Server 的秘诀是什么?