首页 > 其他分享 >jenkins学习笔记之四:jenkins常用pipline DSL方法

jenkins学习笔记之四:jenkins常用pipline DSL方法

时间:2023-02-11 19:34:43浏览次数:63  
标签:false DSL html 构建 BUILD credentialsId 之四 jenkins def

一、Json数据格式化(readJSON)

# 建议使用
def response = readJSON text: "${scanResult}" println(scanResult) //以下为原生方法。不建议使用 import groovy.json.* @NonCPS def GetJson(text){ def prettyJson = JsonOutput.prettyPrint(text) new JsonSlurperClassic().parseText(prettyJson) } 

二、加密使用凭据

语法帮助

 示例:

 生成流水线语法

 简单调用

 

 

 

 三、checkout

/ /Git
checkout([$class: 'GitSCM', branches: [[name: "brnachName"]],
                   doGenerateSubmoduleConfigurations: false,
                   extensions: [],submoduleCfg:[],
                   userRemoteConfigs: [[credentialsId: "${credentialsId} ",
                   url: "${srcUrl}"]]])



//Svn
checkout([$class: 'SubversionSCM', additionalCredentials: [],
                   filterChangelog: false,ignoreDirPropChanges: false,
                   locations: [[credentialsId: "$ {credentialsId}",
                   depthOption: 'infinity', ignoreExternalsOption: true,
                   remote: "$ {svnUrl}"]],workspaceUpdater: [$class:
' CheckoutUpdater']] 

语法参考:

四、生成HTML报告(publishHTML)

安装插件:publish html report

publishHTML([allowMissing: false,
                alwaysLinkToLastBuild: false,
		keepAll: true,
		reportDir: './report/',
		reportFiles: "a.html,b. html",
		reportName: 'InterfaceTestReport',
		reportTitles: 'HTML'])

参数讲解

reportDir,就是你项目中保存html文件的地方,这里写'./report/'是一个相对路径写法,默认从你项目根路面开始
reportFiles,报告名称,这个地方可以同时写多个html文件,逗号隔开。
reportName,这个参数写的字符串会在Jenkins构建Job页面显示的菜单名称,后面会看到这个名称,这个名称可以随意修改 

参考:https://www.jb51.net/article/240961.htm  

五、用户交互-input

def result = input message: '选择xxxxx ',
	ok: '提交',
	parameters: [extendedChoice(description: 'xxxxx',
				    descriptionPropertyValue: '',
				    multiSelectDelimiter: ',',
				    name: 'failePositiveCases',
				    quoteValue: false,
				    saveJSONParameterToFile: false,
				    type: 'PT_CHECKBOX',
				    value: "1,2,3",
				    visibleItemCount: 99)]
println (result)

六、获取构建用户-BuildUser

安装 build user varsVersion插件

wrap([$class: 'BuildUser']){        
     echo "full name is $BUILD_USER" echo "user id is $BUILD_USER_ID" echo "user email is $BUILD_USER_EMAIL" } 

七、发送HTTP请求=httpRequest

 需要安装插件

ApiUrl = "http://xxxxxx/api/project_branches/list?project=$ {projectName}"
Result = httpRequest authentication: 'xxxxxxxxx ',
	     quiet: true,
	     contentType: 'APPLICATION_JSON',
	     url: "${ApiUrl}"  

有语法帮助

 八、邮件通知-email

emailext body: """
<! DOCTYPE html><html>
<head>
<meta charset="UTF-8"></head>
<body leftmargin="8" marginwidth="O" topmargin="8" marginheight="4" offset="O">
	<table width="95%" cellpadding="o" cellspacing="" style="font-size: 11pt; font-family: Tahom
		<tr>
			<td><br />
			<b><font color="#0B610B"">构建信息</font></b></td>
		</tr>
		<tr>
			<td>
				<ul>
					<li>项目名称:$J0B_NAME}</li><li>构建编号:${BUILD_ID</li><li>构建状态:$istatus} </li>
					<li>项目地址:<a href="${BUILD_URL]">${BUILD_URL]</ a></li>
					<li>构建日志:<a href="${BUILD_uRL}console">${BUILD_uRL}console</a></li>
				</ul>
			</td>
		</tr>
		<tr>
	</table>
</body>
/html>"…",
subject: "Jenkins-$iJOB_NAME}项目构建信息",
to: emailUser 

九、清理空间

 

 

 

标签:false,DSL,html,构建,BUILD,credentialsId,之四,jenkins,def
From: https://www.cnblogs.com/panwenbin-logs/p/17112395.html

相关文章

  • jenkins学习笔记之三:使用jenkins共享库实现日志格式化输出
    一、添加AnsiColor插件二、查看插件语法1.打开任意pipline项目配置,找到流水线语法,并点击跳转连接,选择插件,查看帮助三、修改sharelibrary脚本,优化打印方法packag......
  • 修复 KubeSphere 内置 Jenkins 的 Apache Log4j2 漏洞
    作者:老Z,中电信数智科技有限公司山东分公司运维架构师,云原生爱好者,目前专注于云原生运维,云原生领域技术栈涉及Kubernetes、KubeSphere、DevOps、OpenStack、Ansible等。简......
  • 修复 KubeSphere 内置 Jenkins 的 Apache Log4j2 漏洞
    作者:老Z,中电信数智科技有限公司山东分公司运维架构师,云原生爱好者,目前专注于云原生运维,云原生领域技术栈涉及Kubernetes、KubeSphere、DevOps、OpenStack、Ansible等。......
  • jenkins pipline(script)
    二、脚本式Script特点:1.最外层有node{}包裹2.可直接使用groovy语句如何创建最基本的PIpeline直接在JenkinsWebUI网页界面中输入脚本通过创建一个jenkinsfile可以检入项目......
  • jenkins操作mysql
    1、安装mysql所需插件【系统管理】-【插件管理】-【可选插件】处下载安装database与MySQLDatabasePlugin插件。若是无法连接外网,也可通过【系统管理】-【插件管理......
  • mac上的Jenkins安装与使用
    一、Jenkins安装1、输入安装命令:brewinstalljenkins报如下错误:于是乎网上找答案:并输入了命令 brewinstallgettext   ......
  • jenkins变量配置
             ......
  • jenkins接入ldap
    如果没有ldap插件,需要安装ldap插件配置完一定要先测试成功后在退出登录,否则账号无法登录       ......
  • 9 k8s内运行mysql,jenkins
    一kubernetes基于StatefulSet运行MySQL一主多从我这里演示一主一从1.1镜像准备dockerpullregistry.cn-hangzhou.aliyuncs.com/hxpdocker/xtrabackup:1.0dockertag......
  • jenkins单节点构建
      构建脚本cd$WORKSPACE/cmake.&&makecdlibrm/home/sig/libpcb_defect_detect.so*-rfcplibpcb_defect_detect.so*/home/sig/rm/home/sig/ngpoint_sig-......