Open lihongjie0209 opened 4 years ago
Jenkinsfile (Declarative Pipeline)
pipeline {
agent {
docker { image 'node:7-alpine' }
}
stages {
stage('Test') {
steps {
sh 'node --version'
}
}
}
}
It has become increasingly common for code bases to rely on
multiple, different, technologies. For example, a repository might have both a
Java-based back-end API implementation and a JavaScript-based front-end
implementation. Combining Docker and Pipeline allows a Jenkinsfile
to use
multiple types of technologies by combining the agent {}
directive, with
different stages.
Jenkinsfile (Declarative Pipeline)
pipeline {
agent none
stages {
stage('Back-end') {
agent {
docker { image 'maven:3-alpine' }
}
steps {
sh 'mvn --version'
}
}
stage('Front-end') {
agent {
docker { image 'node:14-alpine' }
}
steps {
sh 'node --version'
}
}
}
}
使用docker启动一个jenkins
关键是
-v /var/run/docker.sock:/var/run/docker.sock
, 这样的话jenkins可以通过这个socket与宿主机上的docker通信。