当前位置:   article > 正文

jenkins Pipeline构建.net core 持续集成 CI 简单示例(6)_artifactnumtokeepstr

artifactnumtokeepstr

介绍

  第3章中,jenkins配置了腾讯工蜂的仓库,在此基础上用pipeline来构建.net core的示例,此示例只是演示,真实的生产环境下构建还需要补充和完善。

  项目结构目录如下所示:

  下面是Jenkinsfile文件的配置

  1. pipeline {
  2. agent any
  3. options{
  4. //pipeline超时时间
  5. timeout(time:10, unit:'MINUTES')
  6. //pipeline重试次数
  7. retry(1)
  8. //同一个pipeline,禁止同时执行
  9. disableConcurrentBuilds()
  10. //daysToKeepStr保持构建的天数,numToKeepStr保持构建的最大个数
  11. buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '3', numToKeepStr: '10')
  12. }
  13. stages {
  14. stage('Checkout') {
  15. steps {
  16. //restore会从解决方案或项目的根目录寻找 NuGet.config 文件,如果找不到,则会使用全局的 NuGet.config,也可以自己指定NuGet.config路径
  17. //还可以是还原项目如:dotnet ./jenkenhellowrold/jenkenhellowrold.csproj
  18. //-nowarn不显示警告
  19. bat 'dotnet restore -nowarn:msb3202,nu1503,cs1591 jenkenhellowrold.sln'
  20. //清理解决方案中所有生成的文件,如obj和bin件
  21. bat 'dotnet clean --nologo jenkenhellowrold.sln'
  22. }
  23. }
  24. stage('Build'){
  25. steps{
  26. //生成项目及其所有依赖项
  27. bat 'dotnet build -nowarn:msb3202,nu1503,cs1591 --no-restore jenkenhellowrold.sln'
  28. }
  29. }
  30. stage('Publish'){
  31. steps{
  32. //--nologo不显示启动版权标志或版权消息,。netcore 3.0可用
  33. //-o|--output 输出指定的目录
  34. //-c|--configuration 指定是Debug或Release
  35. bat 'dotnet publish --nologo -nowarn:msb3202,nu1503,cs1591 --no-restore ./jenkenhellowrold/jenkenhellowrold.csproj -c Release -o C:/JenkinsBuilds/'+env.JOB_NAME+'/'+env.BUILD_NUMBER
  36. }
  37. }
  38. }
  39. post{
  40. failure{
  41. echo '执行失败需要发送邮件'
  42. }
  43. success
  44. {
  45. echo '执行成功时需要发送邮件'
  46. }
  47. }
  48. }

 在jenkins中构建后,输出日志,拿 出了重要信息如下所示:

  1. Started by user hushaoren
  2. Obtained Jenkinsfile from git git@git.code.tencent.com:Studies/pipeline-hello-world.git
  3. [Pipeline] Start of Pipeline
  4. [Pipeline] node
  5. Running on Jenkins in C:\Users\AndyH\AppData\Local\Jenkins\.jenkins\workspace\pipeline-hello-world

  1. 源代码拉取后,放在了 C:\Users\AndyH\AppData\Local\Jenkins\.jenkins\workspace\pipeline-hello-world 下,后面的所有dotnet命令都是执行此目录的文件。

  构建成功后,发布的文件在C:/JenkinsBuilds(文件夹是自动创建的),如下所示:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/901943
推荐阅读
相关标签
  

闽ICP备14008679号