加点环境变量
还是基于上篇的扩展,这次加点环境变量并填充一下一些命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
pipeline{ agent any environment { webSrvName = "www.xadocker.cn" lnmpExec = "/bin/lnmp" webUser = 'xadmin' wwwRoot = "/home/wwwroot" testHost = "192.168.1.1" testUser = "testcase" mailToUser = "xad@xadocker.cn" persistFile = 'public' } stages{ stage('Clean'){ steps{ deleteDir() } } stage("Get code"){ steps{ git branch: 'release',credentialsId: '0bd92996-255b-49c4-b86e-92f4a40a7aac', url: 'git@gitlab.xadocker.cn:xadocker/xadocker.git' } } stage("Build"){ steps{ sh label: "install package",script: ''' rm -rf composer.lock /usr/local/bin/composer install -vvv ''' } } stage("Archive"){ steps{ sh label: 'package for tar', script: ''' rm -rf .git && rm -rf otherfile cd ../ tar -zcf ${JOB_BASE_NAMW}.${BUILD_ID}.tar.gz ${JOB_NAME}/ ''' } } stage("Deploy"){ steps{ sh label: "Deploy",script:''' ansible-play -i ./hosts web.yaml ''' } } } } |
加点文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
pipeline{ agent any stages{ stage('test'){ steps{ sh 'mkdir output' writeFile file: "output/userfulfie.txt", text: "this is useful, need to archive it." writeFile file: "output/unlessfile.md", text: "thish is test for unlessfile,so do not archive it." } } stage("archive"){ steps{ archiveArtifacts artifacts: 'output/*.txt', excludes: 'output/*.md' } } } } |