Due to some maintenance issues, this service has been switched in read-only mode, you can find more information about the why

and how to migrate your plugin documentation in this blogpost

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.10 (Aug 20, 2019)

  • Fixed, match count

Version 1.0.8 (Aug 09, 2019)

  • Fixed, close InputStream after read the file‘s content

Version 1.0.7 (June 21, 2019)

  • Fixed, matchCount not to be reset to 1 When editing the configuration file again

Version 1.0.5 (Apr 07, 2019)

  • Fixed, support windows slave, linux master

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. Unknown User (seidzade)


    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 ?

  2. Unknown User (araxes)

    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. Unknown User (moxun)

      Thanks,You counld upgrade to 1.03

  3. Unknown User (araxes)

    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. Unknown User (moxun)

      It was my mistake. 

      Please upgrade to 1.0.4, try again.

    2. Unknown User (moxun)

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

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

  4. Unknown User (araxes)

    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. Unknown User (bkona_alopa)

    I wanted to use for multiple file..?

    Is there any plugin which supports wild card for content replacement

  6. Unknown User (robbatley)

    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.

    1. Unknown User (andreas_burger)

      I am experiencing the same bug. I would be thankful if this get fixed because there is no workaround for this.

  7. Unknown User (kolas)

    I use version 1.0.5. I can use only pre-defines variables (env-vars and from global configuration). Why cannot use standard variable (define in Jenkinsfile) as well? I think that it should be basic purpose. Currently I got message: can't find envVars: [myvar].

    1. Unknown User (matbruc)

      Got the same problem but I resolved it by string concat. 

      def yourVar = params.yourParam
        configs: [                                
            configs: [                                                  
                search: '(Version=)([0-9]+\.[0-9])',                                                           
                replace: '$1"' + yourVar + '"' ,                                                  
                matchCount: 1
            fileEncoding: 'UTF-8',
            filePath: 'yourFile.ext'
  8. Unknown User (araxes)

    The latest version, 1.0.5, has again problems with the 'Match count':

    • 'Match count = 1' doesn't seem to replace anything
    • 'Match count = 0' works

    So, I set 'Match count = 0' and it works, but each time I open the configuration it resets automatically to 1, which breaks the configuration!