pipeline with docker

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

pipeline with docker

John Norris-3
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

--
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: pipeline with docker

Bernardo Vale
Instead of declaring a dockerfile agent try to just add a sh step issuing a docker build

Em ter, 10 de jul de 2018 às 10:26, John Norris <[hidden email]> escreveu:
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

--
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 [hidden email].
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CABxwwGJOZ4DAghcN4MYmxXaBC%3DeQ43PKHf8XELNFwXNcnB1_BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: pipeline with docker

John Norris-3
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?

On Tue, Jul 10, 2018 at 2:32 PM, Bernardo Vale <[hidden email]> wrote:
Instead of declaring a dockerfile agent try to just add a sh step issuing a docker build

Em ter, 10 de jul de 2018 às 10:26, John Norris <[hidden email]> escreveu:
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

--
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 [hidden email].
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CABxwwGJOZ4DAghcN4MYmxXaBC%3DeQ43PKHf8XELNFwXNcnB1_BQ%40mail.gmail.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAP3TUmVnVy%3D1t_BPvCH06BDGTL3Ww%2Bm_%2BQHU5er607DjcPrCdw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: pipeline with docker

Bernardo Vale
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 <[hidden email]> 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?

On Tue, Jul 10, 2018 at 2:32 PM, Bernardo Vale <[hidden email]> wrote:
Instead of declaring a dockerfile agent try to just add a sh step issuing a docker build

Em ter, 10 de jul de 2018 às 10:26, John Norris <[hidden email]> escreveu:
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

--
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 [hidden email].
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.

--
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 [hidden email].

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAP3TUmVnVy%3D1t_BPvCH06BDGTL3Ww%2Bm_%2BQHU5er607DjcPrCdw%40mail.gmail.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 [hidden email].
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.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: pipeline with docker

John Norris-3
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 <[hidden email]> 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 <[hidden email]> 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?

On Tue, Jul 10, 2018 at 2:32 PM, Bernardo Vale <[hidden email]> wrote:
Instead of declaring a dockerfile agent try to just add a sh step issuing a docker build

Em ter, 10 de jul de 2018 às 10:26, John Norris <[hidden email]> escreveu:
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

--
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 [hidden email].
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.

--
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 [hidden email].

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAP3TUmVnVy%3D1t_BPvCH06BDGTL3Ww%2Bm_%2BQHU5er607DjcPrCdw%40mail.gmail.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 [hidden email].
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.

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAP3TUmVJ03q270KHsaiWpX21NiKR5hTOQ7odqayWET2VT39Ptg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: pipeline with docker

John Norris-3
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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?

On Tue, Jul 10, 2018 at 2:32 PM, Bernardo Vale <[hidden email]> wrote:
Instead of declaring a dockerfile agent try to just add a sh step issuing a docker build

Em ter, 10 de jul de 2018 às 10:26, John Norris <[hidden email]> escreveu:
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

--
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 [hidden email].
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.

--
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 [hidden email].

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAP3TUmVnVy%3D1t_BPvCH06BDGTL3Ww%2Bm_%2BQHU5er607DjcPrCdw%40mail.gmail.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 [hidden email].
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.

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAP3TUmV6wJEm_3g1_oc4N9TTRm5GSXtzHcvVJndTHsxsN%2Bx4jQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.