pipeline with docker

41 views
Skip to first unread message

John Norris

unread,
Jul 10, 2018, 9:26:49 AM7/10/18
to Jenkins Users
In the past I have created Jenkins jobs where the application is built using maven after checking out from a git repo and then a docker image is built from a dockerfile, which is pushed to a registry and deployed to test machines.

I was trying to do the same with a jenkinsfile in declarative mode.

I have tried 4 stages; build (do checkout and maven build), docker (using agent dockerfile and then steps for push), test and deploy. 

The problem I am finding is that stage build works - code is checked out and pom.xml is run. But for the docker stage, the code is checked out again, thereby losing the outputs from the build stage.

The Jenkinsfile is

pipeline {
 agent any
 
 stages {
  stage('Build') {
   steps {
    sh 'mvn -Dmaven.test.failure.ignore=true install'
   }
   post {
                success {
                    junit 'target/surefire-reports/**/*.xml'
                }
            }
  }
  stage('Docker image') {
   agent {
    dockerfile {
     additionalBuildArgs  '-t groovytest-$BUILD_NUMBER:jenkins'
    }
   }
   steps {
    echo 'Doing Docker things..'
   }
  }
  stage('Test') {
   steps {
    echo 'Testing..'
   }
  }
  stage('Deploy') {
   steps {
    echo 'Deploying....'
   }
  }
 }
}

So I am obviously doing this incorrectly. Any ideas?
Regards,
John

Bernardo Vale

unread,
Jul 10, 2018, 9:33:04 AM7/10/18
to jenkins...@googlegroups.com
Instead of declaring a dockerfile agent try to just add a sh step issuing a docker build

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/33edc5b3-a812-412b-acc9-f740e41ca078%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Norris

unread,
Jul 10, 2018, 9:36:53 AM7/10/18
to jenkins...@googlegroups.com
That was my original idea but I wasn't sure if the "proper" way was to use the built in docker integration.
It seems as if docker integration with agent is best used to create images for infrastructure rather used for holding the newly built application?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CABxwwGJOZ4DAghcN4MYmxXaBC%3DeQ43PKHf8XELNFwXNcnB1_BQ%40mail.gmail.com.

Bernardo Vale

unread,
Jul 10, 2018, 9:45:04 AM7/10/18
to jenkins...@googlegroups.com
I have exactly the same use case. In my experience, the dockerfile agent will only bring more problems for you. Be simple :)

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAP3TUmVnVy%3D1t_BPvCH06BDGTL3Ww%2Bm_%2BQHU5er607DjcPrCdw%40mail.gmail.com.

John Norris

unread,
Jul 10, 2018, 11:11:33 AM7/10/18
to jenkins...@googlegroups.com
That is the approach I will take then Bernardo. I always find it a problem of how to use the built in stuff that will be just right as long as I stay within its boundaries and how much just to use shell.

On Tue, Jul 10, 2018 at 2:44 PM, Bernardo Vale <bernardosi...@gmail.com> wrote:
I have exactly the same use case. In my experience, the dockerfile agent will only bring more problems for you. Be simple :)

Em ter, 10 de jul de 2018 às 10:36, John Norris <norri...@gmail.com> escreveu:
That was my original idea but I wasn't sure if the "proper" way was to use the built in docker integration.
It seems as if docker integration with agent is best used to create images for infrastructure rather used for holding the newly built application?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CABxwwG%2BMA4JqV64i-Fsm%3D%3Dg%2BdNY1%3Du4mxFpmb-xWb_f77LKHJA%40mail.gmail.com.

John Norris

unread,
Jul 10, 2018, 11:59:15 AM7/10/18
to jenkins...@googlegroups.com
Actually just discovered the "reuseNode true" parameter for agent -> dockerfile. So it must be a param to dockerfile, not agent.
Having said that agent does extra actions that I do not especially want.

On Tue, Jul 10, 2018 at 4:11 PM, John Norris <norri...@gmail.com> wrote:
That is the approach I will take then Bernardo. I always find it a problem of how to use the built in stuff that will be just right as long as I stay within its boundaries and how much just to use shell.
On Tue, Jul 10, 2018 at 2:44 PM, Bernardo Vale <bernardosilveiravale@gmail.com> wrote:
I have exactly the same use case. In my experience, the dockerfile agent will only bring more problems for you. Be simple :)

Em ter, 10 de jul de 2018 às 10:36, John Norris <norri...@gmail.com> escreveu:
That was my original idea but I wasn't sure if the "proper" way was to use the built in docker integration.
It seems as if docker integration with agent is best used to create images for infrastructure rather used for holding the newly built application?

Reply all
Reply to author
Forward
0 new messages