問題1javascript
問題2html
問題1,只出如今測試環境下;問題2,只出如今生產環境下。因此要部署兩套Jenkins,並且對應的Jenkinsfile也區分開java
針對問題搭建的Jenkins:test
node
針對問題搭建的Jenkins:prod
git
針對問題1,配置的Jenkins
針對問題1,測試環境使用的Jenkinsfilees6
//Jenkinsfile def isInChannels(String channel) { Boolean result = false; String channels = "${params.CHANNELS}"; String[] arr = channels.split(','); for (String item in arr) { if (item == channel) { result = true } } return result; } pipeline { agent any parameters { gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH', type: 'PT_BRANCH' } stages { stage('Checkout') { steps { echo ">>>>>>>> Checkout branch ${params.BRANCH}" git branch: "${params.BRANCH}", url: 'http://1*************.git', credentialsId: '***************' } } stage('Install') { when { expression { return params.INSTALL return isInChannels('malllive') } } steps { echo ">>>>>>>> Install ${params.INSTALL}..." sh "cd ${WORKSPACE}" sh "rm -rf node_modules/" sh 'npm install' } } stage('單店') { when { expression { return isInChannels('mall') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/mall" echo ">>>>>>>> build" sh "npm run test:wx:mall:build" // 打包 sh "mv dist/build/mp-weixin dist/build/mall" script { currentBuild.description = currentBuild.description + "<a href='http://**********/job/*************/${BUILD_NUMBER}/execution/node/3/ws/dist/build/mall/*zip*/單店.zip'>下載單店包</a><br/>" // 提供下載包的連接,這個包已經重命名好了,並且是jenkins自帶能夠打包成zip包 } } } stage('單店帶直播') { when { expression { return isInChannels('malllive') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/malllive" echo ">>>>>>>> build" sh "npm run test:wx:malllive:build" sh "mv dist/build/mp-weixin dist/build/malllive" script { currentBuild.description = currentBuild.description + "<a href='http://**********/job/*************/${BUILD_NUMBER}/execution/node/3/ws/dist/build/malllive/*zip*/單店帶直播.zip'>下載單店帶直播包</a><br/>" } } } stage('品牌') { when { expression { return isInChannels('brand') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/brand" echo ">>>>>>>> build" sh "npm run test:wx:brand:build" sh "mv dist/build/mp-weixin dist/build/brand" script { currentBuild.description = currentBuild.description + "<a href='http://**********/job/*************/${BUILD_NUMBER}/execution/node/3/ws/dist/build/brand/*zip*/品牌.zip'>下載品牌包</a><br/>" } } } stage('品牌不帶預訂') { when { expression { return isInChannels('brandnobook') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/brandnobook" echo ">>>>>>>> build" sh "npm run test:wx:brandnobook:build" sh "mv dist/build/mp-weixin dist/build/brandnobook" script { currentBuild.description = currentBuild.description + "<a href='http://**********/job/*************/${BUILD_NUMBER}/execution/node/3/ws/dist/build/brandnobook/*zip*/品牌不帶預訂.zip'>下載品牌不帶預訂包</a><br/>" } } } stage('尊享會') { when { expression { return isInChannels('group') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/group" echo ">>>>>>>> build" sh "npm run test:wx:group:build" sh "mv dist/build/mp-weixin dist/build/group" script { currentBuild.description = currentBuild.description + "<a href='http://**********/job/*************/${BUILD_NUMBER}/execution/node/3/ws/dist/build/group/*zip*/尊享會.zip'>下載尊享會包</a><br/>" } } } stage('預訂') { when { expression { return isInChannels('bookmall') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/bookmall" echo ">>>>>>>> build" sh "npm run test:wx:bookmall:build" sh "mv dist/build/mp-weixin dist/build/bookmall" script { currentBuild.description = currentBuild.description + "<a href='http://**********/job/*************/${BUILD_NUMBER}/execution/node/3/ws/dist/build/bookmall/*zip*/預訂.zip'>下載預訂包</a><br/>" } } } stage('預訂鉑濤') { when { expression { return isInChannels('bookmallbtzh') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/bookmallbtzh" echo ">>>>>>>> build" sh "npm run test:wx:bookmall:build:bt" sh "mv dist/build/mp-weixin dist/build/bookmallbtzh" script { currentBuild.description = currentBuild.description + "<a href='http://**********/job/*************/${BUILD_NUMBER}/execution/node/3/ws/dist/build/bookmallbtzh/*zip*/預訂鉑濤.zip'>下載預訂鉑濤包</a><br/>" } } } } }
針對問題2,配置的Jenkins
shell
針對問題2,生產環境使用的Jenkinsfile,我這裏的文件名叫作Jenkinsfile.prod,跟Jenkins配置的Script Path
須要一致express
// Jenkinsfile.prod def isInChannels(String channel) { Boolean result = false; String channels = "${params.CHANNELS}"; String[] arr = channels.split(','); for (String item in arr) { if (item == channel) { result = true } } return result; } pipeline { agent any parameters { gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH', type: 'PT_BRANCH' } stages { stage('Checkout') { steps { echo ">>>>>>>> Checkout branch ${params.BRANCH}" git branch: "${params.BRANCH}", url: 'http://******************.git', credentialsId: '******************' } } stage('Install') { when { expression { return params.INSTALL } } steps { echo ">>>>>>>> Install ${params.INSTALL}..." sh "cd ${WORKSPACE}" sh "rm -rf node_modules/" sh 'npm install' } } stage('單店') { when { expression { return isInChannels('mall') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/mall" echo ">>>>>>>> build" sh "npm run build:wx:mall" // 打包點單的命令,下面的同理,打包對應的渠道包的命令 sh "mv dist/build/mp-weixin dist/build/mall" sh "node build/upload/index.js -v ${params.VER} -d (生產)(單店)${params.DESC} -i wx*************9560 -p dist/build/mall" sh "wget https://************************" // 若是沒有接入微信第三方平臺,可忽略。由於咱們接入了微信第三方平臺,上傳代碼以後須要把草稿添加到模板,咱們這裏作了一個接口自動添加草稿到模板。 } } stage('單店帶直播') { when { expression { return isInChannels('malllive') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/malllive" echo ">>>>>>>> build" sh "npm run build:wx:malllive" sh "mv dist/build/mp-weixin dist/build/malllive" sh "node build/upload/index.js -v ${params.VER} -d (生產)(單店帶直播)${params.DESC} -i wx*************9560 -p dist/build/malllive" sh "wget https://*************" } } stage('品牌') { when { expression { return isInChannels('brand') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/brand" echo ">>>>>>>> build" sh "npm run build:wx:brand" sh "mv dist/build/mp-weixin dist/build/brand" sh "node build/upload/index.js -v ${params.VER} -d (生產)(品牌)${params.DESC} -i wx*************9560 -p dist/build/brand" sh "wget https://*************" } } stage('品牌不帶預訂') { when { expression { return isInChannels('brandnobook') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/brandnobook" echo ">>>>>>>> build" sh "npm run build:wx:brandnobook" sh "mv dist/build/mp-weixin dist/build/brandnobook" sh "node build/upload/index.js -v ${params.VER} -d (生產)(品牌不帶預訂)${params.DESC} -i wx*************9560 -p dist/build/brandnobook" sh "wget https://*************" } } stage('尊享會') { when { expression { return isInChannels('group') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/group" echo ">>>>>>>> build" sh "npm run build:wx:group" sh "mv dist/build/mp-weixin dist/build/group" sh "node build/upload/index.js -v ${params.VER} -d (生產)(尊享會)${params.DESC} -i wx*************9560 -p dist/build/group" sh "wget https://*************" } } stage('預訂') { when { expression { return isInChannels('bookmall') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/bookmall" echo ">>>>>>>> build" sh "npm run test:wx:bookmall:build" sh "mv dist/build/mp-weixin dist/build/bookmall" sh "node build/upload/index.js -v ${params.VER} -d (生產)(預訂)${params.DESC} -i wx*************93a0 -p dist/build/bookmall" } } stage('預訂鉑濤') { when { expression { return isInChannels('bookmallbtzh') } } steps { echo ">>>>>>>>>> Cleaning...." sh "cd ${WORKSPACE}" sh "rm -rf dist/build/bookmallbtzh" echo ">>>>>>>> build" sh "npm run test:wx:bookmall:build:bt" sh "mv dist/build/mp-weixin dist/build/bookmallbtzh" sh "node build/upload/index.js -v ${params.VER} -d (生產)(預訂鉑濤)${params.DESC} -i wx*************7974 -p dist/build/bookmallbtzh" } } } }
使用miniprogram-ci上傳的腳本npm
// 使用miniprogram-ci上傳 const program = require('commander'); const ci = require('miniprogram-ci'); program .version('1.0.0') .option('-i, --appid [APPID]', '模板小程序appid') .option('-p, --projectpath [PROJECTPATH]', '項目路徑') .option('-v, --ver [VER]', '小程序版本') .option('-d, --desc [DESC]', '版本描述') .parse(process.argv); ;(async () => { const project = new ci.Project({ appid: `${program.appid}`, type: 'miniProgram', projectPath: program.projectpath, privateKeyPath: `build/upload/privatekeys/private.${program.appid}.key`, ignores: ['node_modules/**/*'], }) const uploadResult = await ci.upload({ project, version: program.ver, desc: program.desc, setting: { es6: true, es7: true, autoPrefixWXSS: true, minify: true } }) console.log(uploadResult) })()
isInChannels
方法就是用的groovy語法Extend Choice Parameter
插件