1. 新建任务
2. 配置任务
- 任务名称:自定义
- 构建方式:选择 流水线
3. 配置流水线
在流水线 --> Pipline script 中,编辑脚本
pipeline {
agent any
stages {
stage('Build') {
steps {
# dockerfile 路径
dir('/root/Dockerfile') {
sh 'docker build -t centos-7.9 .'
}
}
}
stage('Publish') {
steps {
sh 'docker tag centos-7.9 harbor.example.com/centos-7.9:latest'
sh 'docker push harbor.example.com/centos-7.9:latest'
}
}
}
}
4. 执行构建
编辑 --> 应用 --> 保存 --> 构建: 立即构建