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.


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



Jenkins version 2.7.3 or newer is required.

Freestyle job configuration

Pipeline job configuration

	configs: [
			configs: [
					search: '(Version=)\\d+.\\d+.\\d+',
					replace: '$11.0.${BUILD_ID}',
					matchCount: 1)
			fileEncoding: 'UTF-8', 
			filePath: 'versions.txt')


Version 1.0.4 (Feb 21, 2019)

  • Fixed, support for absolute path file
  • Fixed, matchCount not to be reset to 1 When editing the configuration file again

Version 1.0.3 (Feb 19, 2019)

  • "File path" can be configured using variables

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. Hi

    Very nice idea , but when tried to use the plugin , got "file not found" exception (FileUtils) : File '/jws/workspace/build_r_image/rpkg_list.txt' does not exist
    at com.mxstrive.jenkins.plugin.contentreplace.ContentReplaceBuilder.replaceFileContent(

    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 ?

  2. The 'file path' field accepts a hard-coded value like:

    \\A21-T1-APP074\E$\D2 DMS 1.1.1\Scripts\applySecurityToFilePlan.dql

    but will not accept environment variables previously injected by the EnvInject Plugin like:

    \\${CS_SERVER}\E$\D2 DMS 1.1.1\Scripts\applySecurityToFilePlan.dql

    This makes the Plugin limited as there is no flexibility on the definition of the file to be processed.

    1. Thanks,You counld upgrade to 1.03

  3. Thanks for the response, but unfortuantelly I installed version 1.03 and it still doesn't work - the 'file path' field with value:

    \\${CS_SERVER}\E$\D2 DMS 1.1.1\Scripts\applySecurityToFilePlan.dql or

    \\$CS_SERVER\E$\D2 DMS 1.1.1\Scripts\applySecurityToFilePlan.dql 

    still gives the error 'file not found' (it would be useful to see if/how the 'file path' was evaluated, to be able to troubleshoot).

    Another annoyance I detected is that even if I set the 'Match count' to 0, each time I go to the configuration page they go back to 1, breaking the functionality (I have to reset them back to 0 manually before saving).

    1. It was my mistake. 

      Please upgrade to 1.0.4, try again.

    2. "\\${CS_SERVER}\E$\D2 DMS 1.1.1\Scripts\applySecurityToFilePlan.dql" is a shared file?

      You should use "\\\\${CS_SERVER}\\..." or  Use / instead\

  4. I confirm that all is working and, even if I use a path to a share, I can use:

    \\${CS_SERVER}\E$\D2 DMS 1.1.1\Scripts\applySecurityToFilePlan.dql

    without the need of duplicating the slashes: "\\\\${CS_SERVER}\\..."

    Thank you very much!

  5. I wanted to use for multiple file..?

    Is there any plugin which supports wild card for content replacement

  6. I am using a Linux Jenkins master with a Windows build agent. When content replace is being run, it seems to be adding a leading / into the path, I am using "E:\Jenkins\workspace\...." in the build step, and I am seeing "

    FATAL: File '/E:/Jenkins/workspace....service.ts' does not exist." in the console output. The file does exist and it works OK on a different Jenkins instance with a windows master.