在docker容器中运行jenkins代理,发出jenkins管道和/var/run/docker.socket

时间:2017-10-02 17:52:59

标签: docker jenkins jenkins-pipeline docker-machine

我已经创建了用于jenkins代理奴隶的图像 这是:https://hub.docker.com/r/kondaurov/jenkins_agent/~/dockerfile/

比我运行它:

docker run -d -p 2222:22 --name=jenkins_agent -v /var/run/docker.sock:/var/run/docker.sock -v kondaurov/jenkins_agent

然后我在jenkins中创建新节点,并通过ssh

成功连接

我尝试运行此管道:

pipeline {

    agent {
            docker {
                label 'agent01'
                image 'hello-world'
            }


    }

    stages {

        stage('Compile') {

            steps {
                sh 'whoami'
                sh 'echo $PATH'

            }

        }


    }

}

agent01 - 是一个带有我的从属图像的容器

但它失败了..

  

用户启动Alexander Mac重播#18

     
    

git rev-parse --is-inside-work-tree #timeout = 10将原点设置为https://github.com/kondaurov-scala/snippets.git     git config remote.origin.url https://github.com/kondaurov-scala/snippets.git #timeout = 10获取     origin ...从原点获取上游变化     git --version #timeout = 10使用GIT_SSH设置凭据     git fetch --tags --progress origin + refs / heads / :refs / remotes / origin / 在存储库origin / 1.1.0中看到分支在存储库origin / master中看到分支看到2远程     分支从中获取Jenkinsfile     5d917470103056b70398465c0d8a56b127f9e036 [Pipeline]节点正在运行     agent01 in     /home/jenkins/workspace/hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q     [Pipeline] {[Pipeline] stage [Pipeline] {(声明:Checkout SCM)     [管道]结账     git rev-parse --is-inside-work-tree #timeout = 10从远程Git存储库中获取更改     git config remote.origin.url https://github.com/kondaurov-scala/snippets.git #timeout = 10获取     没有标签从中获取上游更改     https://github.com/kondaurov-scala/snippets.git     git --version #timeout = 10使用GIT_SSH设置凭据     git fetch --no-tags --progress https://github.com/kondaurov-scala/snippets.git     + refs / heads / :refs / remotes / origin / 签出修订版5d917470103056b70398465c0d8a56b127f9e036(1.1.0)提交消息:" ref"     git config core.sparsecheckout #timetime = 10     git checkout -f 5d917470103056b70398465c0d8a56b127f9e036     git rev-list 5d917470103056b70398465c0d8a56b127f9e036 #timeout = 10 [Pipeline]} [Pipeline] // stage [Pipeline] withEnv [Pipeline] {     [Pipeline] stage [Pipeline] {(声明:Agent Setup)[Pipeline] sh     [hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q]     运行shell脚本     + docker pull hello-world使用默认标签:最新最新:从库/ hello-world拉出5b0f327be733:拉出fs图层5b0f327be733:     验证校验和5b0f327be733:下载完成5b0f327be733:拉     完整文摘:     SHA256:b2ba691d8aac9e5ac3644c0788e3d3823f9e97f757f01d2ddc6eb5458df9d801     状态:已下载更新的hello-world图片:latest [Pipeline]}     [Pipeline] // stage [Pipeline] sh     [hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q]     运行shell脚本     + docker inspect -f。你好,世界 。 [Pipeline] withDockerContainer agent01似乎在容器内运行     c6ad60fd4215a35009accd0be49fbe1ebb583b18b12bf87ba80141b63ae9221a但是     /home/jenkins/workspace/hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q     在[/var/run/docker.sock]中找不到但是     /home/jenkins/workspace/hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q@tmp     在[/var/run/docker.sock] $ docker run -t -d -u中找不到     1000:1000 -w     /home/jenkins/workspace/hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q     -v /home/jenkins/workspace/hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q:/home/jenkins/workspace/hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q:rw,z -v /home/jenkins/workspace/hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q@tmp:/home /jenkins/workspace/hello_world_1.1.0-NAIZYV5H2QFOICXMDYZJM3A6XMQ4YL2QYG5ZWJDDWOEWF27RHL7Q@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 ******** --entrypoint cat hello-world [Pipeline] // withDockerContainer [Pipeline]} [Pipeline] // withEnv     [Pipeline]} [Pipeline] // node [Pipeline] Pipeline End     java.io.IOException:无法运行image' hello-world'。错误:泊坞:     来自守护程序的错误响应:oci运行时错误:container_linux.go:262:     启动容器进程导致" exec:\" cat \&#34 ;:可执行文件没有     发现于$ PATH"。在     org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:138)       在     org.jenkinsci.plugins.docker.workflow.WithContainerStep $ Execution.start(WithContainerStep.java:179)       在org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:224)       在org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:150)       在     org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)       在     org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)       在     org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)       在     org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)       在     com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:19)       在     org.jenkinsci.plugins.docker.workflow.Docker $ Image.inside(JAR:文件:/Users/Shared/Jenkins/Home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar /组织/ jenkinsci /插件/搬运工/工作流/ Docker.groovy:128)       在     org.jenkinsci.plugins.docker.workflow.Docker.node(JAR:文件:/Users/Shared/Jenkins/Home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar /组织/ jenkinsci / plugins / docker / workflow / Docker.groovy:63)at     org.jenkinsci.plugins.docker.workflow.Docker $ Image.inside(JAR:文件:/Users/Shared/Jenkins/Home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar /组织/ jenkinsci /插件/搬运工/工作流/ Docker.groovy:116)       在     org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.DockerPipelineScript.runImage(JAR:文件:/用户/共享/詹金斯/主页/插件/管线模型的定义/ WEB-INF / lib目录/管线模型的定义!.JAR /org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineScript.groovy:57)       在     org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.AbstractDockerPipelineScript.configureRegistry(JAR:文件:/用户/共享/詹金斯/主页/插件/管线模型的定义/ WEB-INF / lib目录/管线模型的定义!.JAR /org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/AbstractDockerPipelineScript.groovy:68)       在     org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.AbstractDockerPipelineScript.run(JAR:文件:/用户/共享/詹金斯/主页/插件/管线模型的定义/ WEB-INF / lib目录/管线模型的定义!.JAR /org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/AbstractDockerPipelineScript.groovy:54)       在     org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.checkoutAndRun(JAR:文件:/Users/Shared/Jenkins/Home/plugins/pipeline-model-extensions/WEB-INF/lib/pipeline-model-extensions.jar !/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy:60)       在 cps.transform (原生方法)中     com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)       在     com.cloudbees.groovy.cps.impl.FunctionCallBlock $ ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)       在     com.cloudbees.groovy.cps.impl.FunctionCallBlock $ ContinuationImpl.fixArg(FunctionCallBlock.java:82)       在sun.reflect.GeneratedMethodAccessor603.invoke(未知来源)at     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       在java.lang.reflect.Method.invoke(Method.java:483)at     com.cloudbees.groovy.cps.impl.ContinuationPtr $ ContinuationImpl.receive(ContinuationPtr.java:72)       在     com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)       在com.cloudbees.groovy.cps.Next.step(Next.java:83)at     com.cloudbees.groovy.cps.Continuable $ 1.call(Continuable.java:174)at at     com.cloudbees.groovy.cps.Continuable $ 1.call(Continuable.java:163)at at     org.codehaus.groovy.runtime.GroovyCategorySupport $ ThreadCategoryInfo.use(GroovyCategorySupport.java:122)       在     org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)       在com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)       在     org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access $ 001(SandboxContinuable.java:19)       在     org.jenkinsci.plugins.workflow.cps.SandboxContinuable $ 1.call(SandboxContinuable.java:35)       在     org.jenkinsci.plugins.workflow.cps.SandboxContinuable $ 1.call(SandboxContinuable.java:32)       在     org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)       在     org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)       在     org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)       在     org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330)       在     org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access $ 100(CpsThreadGroup.java:82)       在     org.jenkinsci.plugins.workflow.cps.CpsThreadGroup $ 2.call(CpsThreadGroup.java:242)       在     org.jenkinsci.plugins.workflow.cps.CpsThreadGroup $ 2.call(CpsThreadGroup.java:230)       在     org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService $ 2.call(CpsVmExecutorService.java:64)       在java.util.concurrent.FutureTask.run(FutureTask.java:266)at     hudson.remoting.SingleLaneExecutorService $ 1.run(SingleLaneExecutorService.java:112)       在     jenkins.util.ContextResettingExecutorService $ 1.run(ContextResettingExecutorService.java:28)       在     java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)       在java.util.concurrent.FutureTask.run(FutureTask.java:266)at     java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)       在     java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)       在java.lang.Thread.run(Thread.java:745)完成:失败

  

3 个答案:

答案 0 :(得分:1)

或许

JENKINS-43590

我的一般建议:如果Image.inside第一次尝试时有效,那就太好了。如果没有,请不要浪费时间尝试使其工作。自己运行docker命令,在Jenkins之外提前测试。

答案 1 :(得分:1)

就我而言,该消息:

  trt  A  B
1   A 96 27
2   B 21 13
3   C NA 34
4   A 43 98
5   B 70 93
6   C NA 64
7   A  2 60
8   B 40 94
9   C NA 11

...是由于以下事实引起的:jenkins从属设备(这是一个docker容器)没有用于工作区的任何卷或装载,因此Jenkins在DiD场景中自动传递的sl01978v-98210312 seems to be running inside container d93e0112b277e94c11bac40af30ddd13ef39cb312caca839497e012cd71bdf86 but /opt/jenkins/workspace/gopvolging_jenkins-somebranch could not be found among [jenkins_slave] but /opt/jenkins/workspace/gopvolging_jenkins-somebranch@tmp could not be found among [jenkins_slave] 选项无法添加。相反,它尝试通过--volume-from中的工作区,但是Jenkins从属容器未共享该工作区,因此它一直在无休止地等待第一个-v命令。为Jenkins工作区添加一个卷即可解决该问题:

sh

(魔法是sl01978v-fbd455e0 seems to be running inside container 0f0090afbcece077f492be581170bf9ffb778c75e23144ccf303e9f47e9cfdd5 $ docker run -t -d -u 1000:1000 -w /opt/jenkins/workspace/gopvolging_jenkins-somebranch --volumes-from 0f0090afbcece077f492be581170bf9ffb778c75e23144ccf303e9f47e9cfdd5 ...

答案 2 :(得分:0)

尝试将从属容器的远程根目录链接到主机/tmp文件夹。 您的情况似乎是/home/jenkins/

docker run -d -p 2222:22 --name=jenkins_agent -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/home/jenkins