I'm trying to do the following
- Checkout the code
- Do some prechecks using some other docker images (don't want to install these on Jenkins node)
- Build jar using docker image
maven:3.6-jdk-8 - Then run
Dockerfileto build app image - Push the image to repository
Now, I don't want to install anything apart from Docker on Jenkins node. I want to run the full pipeline in Docker container to achieve this. What I'm struggling is how to build the 4th step from within the container.
I wrote the Jenkinsfile as below
pipeline { agent none stages { stage('Maven build') { agent { docker { image 'maven:3.6-jdk-8' args '-u root:root' } } steps { checkout( [ $class: 'GitSCM', branches: [ [name: '*/master'] ], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [ [ credentialsId: '<cred-id>', url: '<github-url>'] ] ]) sh ''' set -eux pipefail mvn -e clean install ''' } } stage('Build docker image') { // Which docker image to use? } } } But I'm not sure how to build a docker image within container. The search didn't help that much. I tried using the Jenkins node for the docker image building but it seems I cannot mix and match. I totally understand this is quite an open question but I think it would be helpful to know the straightforward answer(s).