安裝插件
- Pipeline
- Pipeline: Stage View Plugin
創(chuàng)建任務(wù)
配置
- demo
-
開始實(shí)踐
-
拉取git倉(cāng)庫(kù)代碼
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'http://178.119.30.133:8929/root/mytest.git']])
- 通過(guò)SonarQube做質(zhì)量檢測(cè)
sh '/var/jenkins_home/sonar-scanner/bin/sonar-scanner -Dsonar.source=./ -Dsonar.projectname=${JOB_NAME} -Dsonar.projectKey=${JOB_NAME} -Dsonar.login=6c99d1bafedaa4bad18fd63fc9975515fbeb4eab'
- 通過(guò)Docker制作自定義鏡像
sh 'docker build -t ${JOB_NAME}:$tag .'
- 將自定義鏡像推送到Harbor
sh '''docker login -u $harborUser -p $harborPasswd $harborAddress
docker tag $JOB_NAME:$tag $harborAddress/$harborRepo/$JOB_NAME:$tag
docker push $harborAddress/$harborRepo/$JOB_NAME:$tag'''
- 通過(guò)Publish Over SSH通知目標(biāo)服務(wù)器
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-793469.html
sshPublisher(publishers: [sshPublisherDesc(configName: 'test', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'deploy.sh $harborAddress $harborRepo $JOB_NAME $tag $port ', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-793469.html
- Jenkinsfile
pipeline {
agent any
environment {
harborUser = 'admin'
harborPasswd = 'Harbor12345'
harborAddress = '178.119.30.133:80'
harborRepo = 'repo'
}
stages {
stage('拉取git倉(cāng)庫(kù)代碼') {
steps {
checkout scmGit(branches: [[name: '$tag']], extensions: [], userRemoteConfigs: [[url: 'http://178.119.30.133:8929/root/mytest.git']])
}
}
stage('通過(guò)SonarQube做質(zhì)量檢測(cè)') {
steps {
sh '/var/jenkins_home/sonar-scanner/bin/sonar-scanner -Dsonar.source=./ -Dsonar.projectname=${JOB_NAME} -Dsonar.projectKey=${JOB_NAME} -Dsonar.login=6c99d1bafedaa4bad18fd63fc9975515fbeb4eab'
}
}
stage('通過(guò)Docker制作自定義鏡像') {
steps {
sh 'docker build -t ${JOB_NAME}:$tag .'
}
}
stage('將自定義鏡像推送到Harbor') {
steps {
sh '''docker login -u $harborUser -p $harborPasswd $harborAddress
docker tag $JOB_NAME:$tag $harborAddress/$harborRepo/$JOB_NAME:$tag
docker push $harborAddress/$harborRepo/$JOB_NAME:$tag'''
}
}
stage('通過(guò)Publish Over SSH通知目標(biāo)服務(wù)器') {
steps {
sshPublisher(publishers: [sshPublisherDesc(configName: 'test', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "deploy.sh $harborAddress $harborRepo $JOB_NAME $tag $port", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
到了這里,關(guān)于Jenkins之pipeline的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!