00:文章简介
介绍基于Jenkins的GITOPS中的 Jenkins与harbor集成。
在harbor中创建一个制品库和账户
账户:ciadmin
仓库:myapp
01:添加Jenkins凭据
02:增加推送镜像
pipeline {
environment {
appName = "myapp/spring-boot-helloworld"
appVersion = "v0.9.2"
registry = "https://harbor.linux98.com/"
registryCredential = "harbor-myapp-ci-admin"
dockerImage = ""
}
agent {
kubernetes {
inheritFrom 'maven-and-docker'
}
}
stages {
stage('Source') {
steps {
git branch: 'develop', url: 'http://gitlab.linux98.com:8080/root/test.git'
}
}
stage('Build') {
steps {
container('maven'){
sh 'mvn clean test package'
}
}
}
stage('Build app image'){
steps {
container('docker'){
script {
dockerImage = docker.build appName + ":" + appVersion
}
}
}
}
stage('Push app image') {
steps {
container('docker'){
script{
docker.withRegistry( registry, registryCredential ){
dockerImage.push()
}
}
}
}
}
}
}
结果
03:将Jenkinsfile归档到gitlab仓库
将pipeline保存到develop分支中的Jenkinsfile文件中,并提交到gitlab
vim Jenkinsfile
git add .
git commit -m "Add Jenkinsfile"
git push origin develop
测试结果和上面一样,只是将Pipeline与Jenkins分离了,这样更方便开发人员在提交程序时,直接修改Jenkinsfile。
评论区