码迷,mamicode.com
首页 > 其他好文 > 详细

jenkins使用

时间:2021-06-04 19:13:45      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:tab   XML   efi   不同   not   pip   user   声明式   groovy   

https://www.superbin.cc/software/1503.html

yang0826!!!!

env
可以从脚本式流水线中访问的环境变量,例如: env.PATH 或 env.BUILD_ID。 访问内置的全局变量参考页面 ${YOUR_JENKINS_URL}/pipeline-syntax/globals 以获取完整的,最新的,可用于流水线的环境变量列表。

参数以及函数定义
http://groovy-lang.org/syntax.html#_maps


声明式流水线和脚本式流水线
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any

stages {
stage(‘Build‘) {
steps {
echo ‘Building..‘
}
}
stage(‘Test‘) {
steps {
echo ‘Testing..‘
}
}
stage(‘Deploy‘) {
steps {
echo ‘Deploying....‘
}
}
}
}

测试
运行自动化测试是任何成功的持续交付过程的重要组成部分。因此,Jenkins 有许多测试记录,报告和可视化工具,这些都是由各种插件提供的。最基本的,当测试失败时,让 Jenkins 记录这些失败以供汇报以及在 web UI 中可视化是很有用的。下面的例子使用由 JUnit 插件提供的 junit 步骤。


Jenkinsfile (Scripted Pipeline)
node {
checkout scm
/* .. snip .. */
}

Jenkinsfile (Declarative Pipeline)
pipeline {
agent any

stages {
stage(‘Deploy‘) {
when {
expression {
currentBuild.result == null || currentBuild.result == ‘SUCCESS‘
}
}
steps {
sh ‘make publish‘
}
}
}
}

SSH User Private Key 示例

withCredentials(bindings: [sshUserPrivateKey(credentialsId: ‘jenkins-ssh-key-for-abc‘, \
keyFileVariable: ‘SSH_KEY_FOR_ABC‘, \
passphraseVariable: ‘‘, \
usernameVariable: ‘‘)]) {
// some block
}

sshPublisher(publishers: [sshPublisherDesc(configName: ‘lec_dev_deploy_host‘, transfers: [sshTransfer(cleanRemote: false, excludes: ‘‘, execCommand: ‘‘‘
kubectl patch deployment gateway-nginx-deploy -p \"{\\\"spec\\\":{\\\"template\\\":{\\\"metadata\\\":{\\\"annotations\\\":{\\\"date\\\":\\\"`date +‘%s‘`\\\"}}}}}\" -n nlp-ics ‘‘‘, execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: ‘[, ]+‘, remoteDirectory: ‘‘, remoteDirectorySDF: false, removePrefix: ‘‘, sourceFiles: ‘‘)], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])


处理故障
声明式流水线默认通过 post 节段支持强大的故障处理,它允许声明许多不同的 “post 条件”,比如: always、unstable、success、failure 和 changed。流水线语法 提供了关于如何使用各种 post 条件的更多细节。

Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage(‘Test‘) {
steps {
sh ‘make check‘
}
}
}
post {
always {
junit ‘**/target/*.xml‘
}
failure {
mail to: team@example.com, subject: ‘The Pipeline failed :(‘
}
}
}

并行执行
幸运的是,流水线有一个内置的并行执行部分脚本式流水线的功能,通过贴切的名为 parallel 的步骤实现。

 

jenkins使用

标签:tab   XML   efi   不同   not   pip   user   声明式   groovy   

原文地址:https://www.cnblogs.com/L-O-N/p/14848095.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!