Jenkins Kubernetes plugin: How to build image from Dockerfile and run steps inside the image
As pointed out by Matt in the comments this works:
pipeline { agent { kubernetes { //cloud 'kubernetes' label 'mypod' yaml """apiVersion: v1kind: Podspec: containers: - name: docker image: docker:1.11 command: ['cat'] tty: true volumeMounts: - name: dockersock mountPath: /var/run/docker.sock volumes: - name: dockersock hostPath: path: /var/run/docker.sock""" } } stages { stage('Build Docker image') { steps { git 'https://github.com/jenkinsci/docker-jnlp-slave.git' container('docker') { script { def image = docker.build('jenkins/jnlp-slave') image.inside() { sh "whoami" } } } } } }}
container('docker') { script { def image = docker.build("cusdock","CustomImage") image.inside(){ sh "docker info" } } }
Here CustomImage is the directory inside your git repo which contains Dockerfile which will build your custom image.That image will be build and tagged as cusdockdocker info will be run inside your custom docker image.