Jenkins 流水线语法 02 片段生成器和声明式语法生成器

网友投稿 1093 2022-11-07

Jenkins 流水线语法 02 片段生成器和声明式语法生成器

Jenkins 流水线语法 02 片段生成器和声明式语法生成器

Pipeline 开发工具

片段生成器

有些pipeline代码不是自己去写的,是要工具帮我们生成的,只需要知道怎么生成就行了

Jenkins会安装很多插件,有些插件会为你提供一些方法,也就是代码化的方法让你去使用片段生成器(下面就是安装好的插件为我们提供的所有功能)

流水线代码片段生成器, 非常好用。在这里可以找到每个插件以及Jenkins内置的方法的使用方法。使用片段生成器可以根据个人需要生成方法,有些方法来源于插件,则需要先安装相关的插件才能使用哦。

使用checkout生成器-gitlab代码

checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'dc735f39-1cef-4a12-a499-6c873b82adcc', url: '{ agent any stages { stage('getCode') { steps { checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'dc735f39-1cef-4a12-a499-6c873b82adcc', url: ' } } }}Started by user adminRunning in Durability level: MAX_SURVIVABILITY[Pipeline] Start of Pipeline[Pipeline] nodeRunning on build-01 in /data/cicd/jenkinsagent/workspace/pipeline-test[Pipeline] {[Pipeline] stage[Pipeline] { (getCode)[Pipeline] checkoutThe recommended git tool is: NONEusing credential dc735f39-1cef-4a12-a499-6c873b82adccCloning the remote Git repositoryAvoid second fetchChecking out Revision dc647d4ef52aadabf75db582393156decc4ca6a3 (refs/remotes/origin/master)Commit message: "Update version"First time build. Skipping changelog.[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineCloning repository > git init /data/cicd/jenkinsagent/workspace/pipeline-test # timeout=10Fetching upstream changes from > git --version # timeout=10 > git --version # 'git version 2.7.4'using GIT_ASKPASS to set credentials git-lab-admin-user > git fetch --tags --progress +refs/heads/*:refs/remotes/origin/* # timeout=10 > git config remote.origin.url # timeout=10 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10 > git config core.sparsecheckout # timeout=10 > git checkout -f dc647d4ef52aadabf75db582393156decc4ca6a3 # timeout=10Finished: SUCCESS

使用sh生成器生成shell脚本

pipeline { agent any stages { stage('getCode') { steps { sh 'pwd' } } }}Started by user adminRunning in Durability level: MAX_SURVIVABILITY[Pipeline] Start of Pipeline[Pipeline] nodeRunning on Jenkins in /var/jenkins_home/workspace/pipeline-test[Pipeline] {[Pipeline] stage[Pipeline] { (getCode)[Pipeline] sh+ pwd/var/jenkins_home/workspace/pipeline-test[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS

pipeline { agent any stages { stage('getCode') { steps { script{ sh ''' date pwd echo "hh" ''' } } } }}

Started by user adminRunning in Durability level: MAX_SURVIVABILITY[Pipeline] Start of Pipeline[Pipeline] nodeRunning on Jenkins in /var/jenkins_home/workspace/pipeline-test[Pipeline] {[Pipeline] stage[Pipeline] { (getCode)[Pipeline] script[Pipeline] {[Pipeline] sh+ dateTue May 18 11:36:36 UTC 2021+ pwd/var/jenkins_home/workspace/pipeline-test+ echo hhhh[Pipeline] }[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS

stages { stage('build') { steps { // One or more steps need to be included within the steps block. } }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Ceph RBD块存储 快照创建和克隆
下一篇:Kubernetes 检查YAML文件安全配置:kubesec
相关文章

 发表评论

暂时没有评论,来抢沙发吧~