跳至主要內容

jenkins推送harbor

brinishness...小于 1 分钟Jenkinsjenkinspublishharbor

jenkins推送harbor

1.拉取代码

git branch: 'master', credentialsId: 'XXXXXXXXXXXXXXXXXXXXXXXXX', url: 'http://xxxx.xxxx.xxxx/xxx/demo.git'

2.构建镜像

script {
    app = docker.build("xx/xxx:$Tag", ".")
}

3.推送到harbor (xxxxxxxxxxxxxxxxxxxxxxxxxx为凭据ID)

script {
    docker.withRegistry("http://xxx.xxxx.xxxx", 'xxxxxxxxxxxxxxxxxxxxxxxxxx'){
        app.push()
    }
}

4.删除本地镜像

pipeline {
    agent {
        docker {
            image "python:3.7"
        }
    }
    environment {
        app = null
    }
    stages {
        stage("拉取代码"){
            steps {
                git branch: 'master', credentialsId: 'XXXXXXXXXXXXXXXXXXXXXXXXX', url: 'http://xxxx.xxxx.xxxx/xxx/demo.git'
            }
        }
        stage("构建镜像"){
            steps {
                script {
                    app = docker.build("xx/xxx:$Tag", ".")
                }
            }
        }
        stage('推送镜像'){
            steps {
                script {
                    docker.withRegistry("http://xxx.xxxx.xxxx", 'xxxxxxxxxxxxxxxxxxxxxxxxxx'){
                        app.push()
                    }
                }
            }
        }
        stage('删除本地镜像'){
            steps {
                sh "docker rmi xxx.xxxx.xxxx/xx/"+"xxx:$Tag"
            }
        }
    }
}
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.5