Jenkins 构建容器镜像

201 阅读1分钟

1. 新建任务

图片1.png

2. 配置任务

企业微信截图_1691054501633.png

  • 任务名称:自定义
  • 构建方式:选择 流水线

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. 执行构建

编辑 --> 应用 --> 保存 --> 构建: 立即构建

5. 构建成功

企业微信截图_16910551584767.png