pipeline { //使用标签 'master' 的节点 agent {label 'master'} //环境变量 environment { //成功运行特征 JEN_FEATURE = '' //日志路径 JEN_LOG = '' } stages { stage ('编译打包'){ steps { sh 'cd /home/编译目录 && sudo git pull' sh 'sh gradle-apk.sh' } }
stage ('上传'){ steps { sh 'sshpass -p "password" scp /home/编译目录/app/build/outputs/apk/release/app-release.apk [email protected]:/home/上传目录/app-release.apk' } }
stage ('生成qr'){ steps { echo "生成test qr" sh "pwd && myqr 'https://www.nginx.com/app-release.apk' -n qrcode-`date +'%Y-%m-%d-%H%M%S'`.png -d /home/code/image" sh "cd /home/code/image && git add ." sh "cd /home/code/image && git commit -m 'new images'" sh "cd /home/code/image && git push origin main" echo "结束 end" } } }
post { success { script { env.DATETIME = sh(script:"date", returnStdout: true).trim() env.QRCODE = sh(script:"ls -lhst /home/code/image | awk 'NR==2' | awk '{print \$10}'",returnStdout: true).trim() def job_name = "# ${JOB_NAME} 流水线 执行成功" def jenkinsid = """构建: 第 ${BUILD_ID} 次执行""" def JEN_production = "> 部署节点: jenkins" def build_url = "> 部署详情: [详情](${BUILD_URL})" def jen_date = "> 执行时间: ${env.DATETIME}" def jen_qrcode = "![qr](https://gitlab.com/jobcher/image/-/raw/main/${env.QRCODE})"
dingtalk ( robot: 'e3999649-d3f-钉钉key-4c57333a327b', type: 'MARKDOWN', title: job_name, text: [ job_name, jenkinsid, '', '---', jen_qrcode, JEN_production, '', build_url, '', jen_date ], at: [ '手机号' ] ) } } failure { script { env.DATETIME = sh(script:"date", returnStdout: true).trim() def job_name = "# ${JOB_NAME} 流水线 执行失败" def jenkinsid = """构建: 第 ${BUILD_ID} 次执行""" def JEN_production = "> 部署节点: jenkins" def build_url = "> 部署详情: [详情](${BUILD_URL})" def jen_date = "> 执行时间: ${env.DATETIME}"
dingtalk ( robot: 'e3999649-d3f-钉钉key-4c57333a327b', type: 'MARKDOWN', title: job_name, text: [ job_name, jenkinsid, '', '---', JEN_production, '', build_url, '', jen_date ], at: [ '手机号' ] ) } } } } |