0%

在Jenkins中使用docker

配置插件 Global Tool Configuration

添加一个Docker安装,将其命名为:docker

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
pipeline {
agent any
options {
timestamps()
timeout(30)
}

stages {
stage("Check out") {
steps {
git credentialsId: 'dev', url: 'git@10.1.11.112:psp/system-management-web-portal.git', branch: 'dev'
}
}

stage('Build') {
steps {
nodejs('nodejs') {
sh 'npm install'
sh 'npm run build'
}
script {
docker.withTool('docker') {
withDockerServer([uri: 'tcp://192.168.55.207:2375', credentialsId: null]) {
sh 'docker build . -t psp.system-management-web-portal'
}
}
}

}
}

stage('Deploy') {
steps {
script {
docker.withTool('docker') {
withDockerServer([uri: 'tcp://192.168.55.207:2375', credentialsId: null]) {
sh 'docker rm -f psp.system-management-web-portal || echo "no container exists" '
sh 'docker run -d --network comall --ip 10.1.200.10 --name psp.system-management-web-portal psp.system-management-web-portal'
}
}
}
}
}
}
}