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

一、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 

九、清理空间

 

 

 

posted @ 2023-02-11 19:18  百衲本  阅读(305)  评论(1编辑  收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码