配置文件替换

Content Replace Plugin 作为一个 Jenkins 插件,用于构建过程中对一些文本文件内容的修改替换。

比如:每次构件时需要在指定的文件中修改版本号、只在持续集成时写入一些敏感信息等,适合构建工具不支持或编写代码不方便的内容修改

插件有以下几个特点:

  1. 支持多文件内容替换
  2. 支持常见编码格式选择
  3. 支持正则表达式匹配
  4. 支持使用变量设置内容
  5. 支持设置匹配次数,实际替换次数与设置不一致时,构建失败
  6. 支持多种任务类型设置
  7. 支持子节点、多平台

Content Replace Plugin支持 Freestyle job 和 Pipeline job 两种构件任务的设置方式

Freestyle job configuration

Pipeline job configuration

contentReplace(
	configs: [
		fileContentReplaceConfig(
			configs: [
				fileContentReplaceItemConfig( 
					search: '(Version=)\\d+.\\d+.\\d+',
					replace: '$11.0.${BUILD_ID}',
					matchCount: 1)
				],
			fileEncoding: 'UTF-8', 
			filePath: 'versions.txt')
		])
发布了9 篇原创文章 · 获赞 20 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/Aaron_Zhang939/article/details/103454267