Skip to end of metadata
Go to start of metadata

Plugin Information

View Content Replace on the plugin site for more information.

A plugin for Jenkins allows you to replace file content with regex expressions.

Features

  • Regex expression for search. e.g. (Version=)([0-9]+\.[0-9]+\.[0-9]+)
  • You can use variables enclosed in ${}

Requirements

Jenkins

Jenkins version 2.7.3 or newer is required.


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')
		])

Changelog

Version 1.0.2 (Oct 26, 2018)

  • Add "Match count" config

Version 1.0.1 (Aug 22, 2018)

  • Simply replace the contents of the specified encoded file
  • No labels

1 Comment

  1. Hi

    Very nice idea , but when tried to use the plugin , got "file not found" exception (FileUtils) :


    java.io.FileNotFoundException: File '/jws/workspace/build_r_image/rpkg_list.txt' does not exist
    at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:299)
    at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1711)
    at com.mxstrive.jenkins.plugin.contentreplace.ContentReplaceBuilder.replaceFileContent(ContentReplaceBuilder.java:69)


    Using Jenkins ver 2.138.3

    My pipeline job config :

    stage('Setup Image') {
    			steps {
    				contentReplace(configs: [fileContentReplaceConfig(configs: 
    	                [fileContentReplaceItemConfig(matchCount: 1, replace: 'ENV R-VERSION ${R-VERSION}', search: 'ENV R-VERSION'),
    	                fileContentReplaceItemConfig(matchCount: 1, replace: 'ENV PYTHON-VERSION ${PYTHON-VERSION}', search: 'ENV PYTHON-VERSION')],
    	                fileEncoding: 'UTF-8', filePath: 'rpkg_list.txt')])
    			}
    		}


    File is located in path and editable by root , which is run remoting on this jenkins slave:

    ll /jws/workspace/build_r_image/rpkg_list.txt
    -rw-r--r--. 1 root root 849 Dec  1 13:25 /jws/workspace/build_r_image/rpkg_list.txt


    What can be a problem ?