jenkins pipeline 正对java 项目 打war ,jar ,或者多级子目录进行打包
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jenkins pipeline 正对java 项目 打war ,jar ,或者多级子目录进行打包,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3817字,纯文字阅读大概需要6分钟。
内容图文
通过jenkins pipeline 中 groovy 语言的一些方法,编写统一的java pipeline 打包段。
stage('up') { steps { script { def sub_build_path = '' for (val in BUILD_SCRIPTS.split(';|&&')){ if (val.contains('cd') && val.split(' ').size() >= 2){ for ( sub_val in val.split(' ')){ if (sub_val != '' && ! sub_val.contains('cd') ){ sub_build_path +=sub_val if (! sub_build_path.endsWith('/')){ sub_build_path +='/' } } } } } target = sh returnStdout: true,script: "find $sub_build_path -type d -name target" if (target != '' ){ sub_build_path +='target/' }else{ // for grandle sub_build_path +='build/libs/' } rvfind = sh returnStdout: true,script: "find $sub_build_path -name '*.war'" if (rvfind == ''){ outfile = "${sourcefile}.jar" rvfind = sh returnStdout: true, script: "ls -l $sub_build_path| awk '{print \$NF}' | egrep '*.jar\$' | awk -v ORS=' ' '{print \$0}' " } rvfind = rvfind.trim() sh "if test ! -d ${sourcefile};then mkdir ${sourcefile};else rm -rf ./${sourcefile}/*;fi;" if ( outfile.contains('war')){ sh """ unzip -q -d ${sourcefile} ${rvfind} """ }else{ dir(sourcefile){ for (ofile in rvfind.split(' ')){ if (ofile != ''){ pathfile = '../' + sub_build_path + ofile sh """ /bin/cp -f $pathfile .; """ } } } } sh """ zip -qry $zipfile ${sourcefile} """ } stash includes: "$zipfile", name: "$zipfile" } }
stage('service oper'){ //agent {lable 'node_label'} steps{ unstash "$zipfile" sh """ sudo su -c "PATH=$PATH;${stop_script} && echo 'STOP Proceess success' ||echo 'STOP Process failure '" """ script{ if (! unzip_path.endsWith('/')){ unzip_path += '/' } if (unzip_path.contains('ROOT')) { sh """ sudo su -c "cd ${unzip_path};rm -rf ./*;unzip -oq ${workspace}/$zipfile;mv ${sourcefile}/* .;rm -rf ./${sourcefile}" """ }else if (outfile.endsWith('jar')){ for (ofile in rvfind.split(' ')){ sh "if test -f ${unzip_path}$ofile;then rm -f ${unzip_path}$ofile;fi" } sh """ sudo su -c "cd ${unzip_path};unzip -oq ${workspace}/$zipfile;mv ${sourcefile}/* .;rm -rf ./${sourcefile}" """ }else{ sh """ sudo su -c "cd ${unzip_path};rm -rf ./$sourcefile;unzip -oq ${workspace}/$zipfile" """ } } sh """ sudo su -c "PATH=$PATH;${start_script}" """ } }
内容总结
以上是互联网集市为您收集整理的jenkins pipeline 正对java 项目 打war ,jar ,或者多级子目录进行打包全部内容,希望文章能够帮你解决jenkins pipeline 正对java 项目 打war ,jar ,或者多级子目录进行打包所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。