Jenkins Pipeline executes docker container
Jenkins Pipeline 1
pipeline {
agent {
docker { image 'maven:latest' }
}
stages {
stage('Test') {
steps {
sh 'mvn -version'
}
}
}
}
Jenkins Pipeline in kubernetes context
Jenkins supports cloud environments like Kubernetes. The Jenkins Kubernetes plugin is a key to server less world. There are minor changes to the Pipeline code. Now, the cloud will instantiate the docker container.
Jenkins Pipeline 2
pipeline {
agent {
kubernetes {
defaultContainer 'maven'
yamlFile 'KubernetesPod.yaml'
}
}
stages {
stage('Run maven') {
steps {
sh 'mvn -version'
}
}
stage('Run shell') {
container('mycontainer') {
sh 'echo hello world'
}
}
}
}
Jenkins Pipeline stash and unstash
Jenkins Pipeline 3
pipeline {
...
stages {
stage('step 1') {
steps {
...
stash includes: 'dist/**/*', name: 'FOOBAR'
}
}
stage('step 2') {
unstash 'FOOBAR'
}
}
}
0 Comments