1

I am currently trying out my first Jenkins project. Which is supposed to be a simple create and publish a Docker Image if there's a commit on Github. I'm using an EC2 instance which has Jenkins and Docker installed.

Unfortunately, whenever I try to build in Jenkins I keep getting an error during the test stage. Here are the logs:

[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/Jenkins-Project
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Clone repository)
[Pipeline] checkout
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/Jenkins-Project/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/Momo979/JenkinsTest.git # timeout=10
Fetching upstream changes from https://github.com/Momo979/JenkinsTest.git
 > git --version # timeout=10
 > git --version # 'git version 2.32.0'
 > git fetch --tags --force --progress -- https://github.com/Momo979/JenkinsTest.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision d0bdbc09d8ffbb83306c1121adfacae6ccd4619c (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f d0bdbc09d8ffbb83306c1121adfacae6ccd4619c # timeout=10
Commit message: "Added Jenkins File"
 > git rev-list --no-walk d0bdbc09d8ffbb83306c1121adfacae6ccd4619c # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build image)
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker build -t momo979/purple-beard-team-2 .
Sending build context to Docker daemon  96.77kB

Step 1/7 : FROM ubuntu:18.04
 ---> dcf4d4bef137
Step 2/7 : RUN apt-get update -y &&  apt-get install apache2 curl -y --no-install-recommends
 ---> Using cache
 ---> dd58d308db53
Step 3/7 : WORKDIR /var/www/html/
 ---> Using cache
 ---> 45b0caaa0bdb
Step 4/7 : COPY index.html .
 ---> Using cache
 ---> 5b883f6013e6
Step 5/7 : HEALTHCHECK CMD curl -f http://localhost/ || exit 1
 ---> Using cache
 ---> 488aa2c526a1
Step 6/7 : EXPOSE 80
 ---> Using cache
 ---> 4ebb1d368fde
Step 7/7 : ENTRYPOINT [ "apache2ctl", "-D", "FOREGROUND" ]
 ---> Using cache
 ---> 764571e46e46
Successfully built 764571e46e46
Successfully tagged momo979/purple-beard-team-2:latest
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test image)
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . momo979/purple-beard-team-2
.
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 995:993 -w /var/lib/jenkins/workspace/Jenkins-Project -v /var/lib/jenkins/workspace/Jenkins-Project:/var/lib/jenkins/workspace/Jenkins-Project:rw,z -v /var/lib/jenkins/workspace/Jenkins-Project@tmp:/var/lib/jenkins/workspace/Jenkins-Project@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 ******** -e ******** momo979/purple-beard-team-2 cat
$ docker top 3cad99c25fab50292e044245cea0f082016e2285c9576e75c2c565be1e295736 -eo pid,comm
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.IOException: Failed to run top '3cad99c25fab50292e044245cea0f082016e2285c9576e75c2c565be1e295736'. Error: Error response from daemon: Container 3cad99c25fab50292e044245cea0f082016e2285c9576e75c2c565be1e295736 is not running
    at org.jenkinsci.plugins.docker.workflow.client.DockerClient.listProcess(DockerClient.java:152)
    at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:200)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:319)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:193)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:140)
    at org.jenkinsci.plugins.docker.workflow.Docker.node(Docker.groovy:66)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:125)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy)
    at WorkflowScript.run(WorkflowScript:18)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
    at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:402)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:314)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:278)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
    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

Dockerfile

FROM ubuntu:18.04
RUN apt-get update -y && \
 apt-get install apache2 curl -y --no-install-recommends
WORKDIR /var/www/html/
COPY index.html .
HEALTHCHECK CMD curl -f http://localhost/ || exit 1
EXPOSE 80
ENTRYPOINT [ "apache2ctl", "-D", "FOREGROUND" ]

JenkinsFile

node {
    def app

    stage('Clone repository') {
      

        checkout scm
    }

    stage('Build image') {
  
       app = docker.build("momo979/purple-beard-team-2")
    }

    stage('Test image') {
  

        app.inside {
            sh 'echo "Tests passed"'
        }
    }

    stage('Push image') {
        
        docker.withRegistry('https://registry.hub.docker.com', 'Dockerhub') {
            app.push("${env.BUILD_NUMBER}")
            app.push("latest")
        }
    }
}

The image creates a static HTML page.

Thanks for your help!

1 Answer 1

1

The issue here is the image has an entry point, which is not supported by the inside method.

When using inside with a Docker image that has an ENTRYPOINT instruction, we need to add --entrypoint='' to the run arguments, for example in the OP case:

app.inside("--entrypoint=''")  {
    sh 'echo "Tests passed"'
}

(reposting as correct user instead of new user...)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .