前言
本節(jié)內(nèi)容我們使用另外一種方式pipeline實(shí)現(xiàn)項(xiàng)目的流水線部署發(fā)布,Jenkins Pipeline是一種允許以代碼方式定義持續(xù)集成和持續(xù)交付流水線的工具。通過Jenkins Pipeline,可以將整個(gè)項(xiàng)目的構(gòu)建、測(cè)試和部署過程以腳本的形式寫入Jenkinsfile中,實(shí)現(xiàn)對(duì)整個(gè)流程的可視化管理和控制。在 Jenkins Pipeline中,可以定義不同的階段(stage)、步驟(step)、參數(shù)(parameters)、環(huán)境變量(environment variables)等,以實(shí)現(xiàn)自動(dòng)化構(gòu)建、測(cè)試和部署過程。還可以通過條件判斷、循環(huán)等控制結(jié)構(gòu)來(lái)實(shí)現(xiàn)流水線的靈活控制。
正文
①創(chuàng)建一個(gè)流水線pipeline方式的項(xiàng)目
②填寫描述信息和構(gòu)建的策略,此步驟可跳過
③ 使用流水線的Pipeline script方式構(gòu)建一個(gè)maven項(xiàng)目
- 構(gòu)建腳本
pipeline { agent any stages { stage('拉取代碼') { steps { echo '========================拉取代碼========================' checkout([ $class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg:[], userRemoteConfigs: [[credentialsId: 'gitee', url:'https://gitee.com/northcangap/ht-atp.git']] ]) } } stage('編譯構(gòu)建') { steps { echo '========================編譯構(gòu)建========================' sh 'cd ht-atp-security && mvn clean package -Dmaven.test.skip=true' } } stage('部署安裝') { steps { echo '========================部署安裝========================' sshPublisher( continueOnError: false, failOnError: true, publishers: [ sshPublisherDesc( configName: "ht-atp", transfers: [ sshTransfer( sourceFiles: "ht-atp-security/target/*.jar", removePrefix: "ht-atp-security/target", remoteDirectory: "/pipeline", execCommand: "cd /ht/pipeline && sh start.sh", execTimeout: 12000 ) ] ) ] ) } } } }
- 使用git拉取代碼
- 使用maven命令構(gòu)建項(xiàng)目
- 使用sshPublisher組件將構(gòu)建好的項(xiàng)目發(fā)布到遠(yuǎn)程服務(wù)器
④ 點(diǎn)擊立即構(gòu)建,構(gòu)建該流水線項(xiàng)目
⑤查看構(gòu)建的流水線項(xiàng)目日志
⑦ 訪問項(xiàng)目
⑧方式二:流水線使用Pipeline script from SCM方式創(chuàng)建,配置源碼地址
⑨ 配置Jenkinsfile流水線腳本路徑
⑩?在項(xiàng)目的源碼路徑下創(chuàng)建一個(gè)Jenkinsfile文件,文件內(nèi)容同上,并上傳到源碼庫(kù),構(gòu)建時(shí),會(huì)使用此文件完成流水線項(xiàng)目的發(fā)布
?同樣也可以部署發(fā)布成功,一般更推薦使用方式二實(shí)現(xiàn)
??關(guān)于pipeline的流水線語(yǔ)法可參考其提供的DSL流水線語(yǔ)法
? 前端vue項(xiàng)目的部署腳本
pipeline {
agent any
stages {
stage('拉取代碼') {
steps {
echo '========================拉取代碼========================'
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg:[],
userRemoteConfigs: [[credentialsId: 'gitee', url:'https://gitee.com/northcangap/ht-atp.git']]
])
}
}
stage('編譯構(gòu)建') {
steps {
echo '========================編譯構(gòu)建========================'
sh 'cd ht-atp-app && npm i -f && npm run build'
}
}
stage('部署安裝') {
steps {
echo '========================部署安裝========================'
sshPublisher(
continueOnError: false,
failOnError: true,
publishers: [
sshPublisherDesc(
configName: "ht-atp",
transfers: [
sshTransfer(
sourceFiles: "ht-atp-app/dist/**",
removePrefix: "ht-atp-app/dist",
remoteDirectory: "/pipeline/ht-app"
)
]
)
]
)
}
}
}
}
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-831733.html
結(jié)語(yǔ)
至此,關(guān)于jenkins流水線使用pipeline方式發(fā)布項(xiàng)目的內(nèi)容到這里就結(jié)束了,我們下期見。。。。。。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-831733.html
到了這里,關(guān)于(十四)devops持續(xù)集成開發(fā)——jenkins流水線使用pipeline方式發(fā)布項(xiàng)目的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!