Skip to end of metadata
Go to start of metadata

Plugin Information

View File Operations on the plugin site for more information.

About

This plugin's main goal is to provide File Operations as Build Step.

Following Operations implemented:

1) File Copy Operation

2) File Delete Operation

3) File Create Operation

4) File Download Operation

5) File Transform Operation

6) File UnTar Operation

7) File UnZip Operation

8) Folder Create Operation

9) Folder Copy Operation

10) Folder Delete Operation

11) File Join

12) File Properties To Json

13) File Zip Operation

14) File Rename Operation

15) Folder Rename Operation

This will be helpful for doing cross platform file operations. No need to search for Nix or Win commands to do file operations.

Screenshot

Release 1.7 (4 September 2017)

  • Added File Rename Operation
  • Added Folder Rename Operation

Release 1.6 (4 May 2017)

  • Fixed download failed due to empty credentials even though if it open for public

Release 1.5 (7 April 2017)

  • Added File Zip Operation

Release 1.4 (5 March 2017)

  • Added Symbols for Jenkins pipeline

Release 1.3 (3 October 2016)

  • Added Job DSL support

Release 1.2 (26 June 2016)

  • Added 11 & 12 operations

Release 1.1 (28 May 2016)

  • Added support for pipeline

Release 1.0 (22 April 2016)

  • First public release with 1 to 10 operations

22 Comments

  1. Hi,

    could you please add to the manual how to use plugin in pipeline?

    thanks

  2. 1. Can this be used to copy files from outside the workspace? When using as a build step I got:

    Got: Expecting Ant GLOB pattern, but saw 'C:/Temp/*.xml'

    2. How do I use this in a Jenkins Pipeline / Jenkinsfile script? (I assume that's what you mean by DSL)

    Using as documented

    Jenkinsfile
    freeStyleJob('FileOperationsJob') {
        steps {
            fileOperations {
                fileCopyOperation('testdsl.txt','','.',false)
            }
        }
    }
    

    Results in:

    java.lang.IllegalArgumentException: Expected named arguments but got [FileOperationsJob, org.jenkinsci.plugins.workflow.cps.CpsClosure2@edf76f]

    Using inside my script

    Jenkinsfile
    node {
        fileCopyOperation('C:\\Temp\\*.xml', '', '.', false)
    }
    

    Results in:

    java.lang.NoSuchMethodError: No such DSL method 'fileCopyOperation' found among steps [...
    1. step([$class: 'FileOperationsBuilder', fileOperations: [[$class: 'FileCopyOperation', excludes: '', flattenFiles: false, includes: '**/*.xml', targetLocation: '.']]])

      To FileOperations in Jenkins Pipeline, above is the syntax for FileCopyOperation. The above code can be generated using pipeline-syntax.

      1. fileOperations ([
        fileCopyOperation (includes: "${WORKSPACE}/${PROJECT_NAME}/**",  targetLocation: "${WORKSPACE}/${PROJECT_NAME}-build/source")
        ])


        I want to copy all file from ${WORKSPACE}/${PROJECT_NAME}/ to ${WORKSPACE}/${PROJECT_NAME}-build/source but its not working. 

        If I try "includes: "**/${PROJECT_NAME}/**" it will create a directory {PROJECT_NAME} inside the target folder 


        Thanks in advance

        Sanjeev

  3. Hi.

    Can this plugin rename the files and folders?.

    Can you can add this feature?

     

  4. Greetings, I have downloaded the latest version of the plugin, and could not find Zip feature in the operations list. 

    Is it consolidated into File Join operation? 

  5. Could you please allow for greater control in how the File Zip archives a directory? I want the contents of my target folder to end up in the ZIP file's root directory, like \{MyFilesAndSubDirectories} - not \{MyFolder}\{MyFilesAndSubDirectories}.

    I wouldn't normally ask but I have no other easy way to achieve this with Jenkins in Windows than by using your fine plugin.

    1. Raise ticket in JIRA with requirement description.

  6. I am trying to create a file using you plugin as follows:

    fileOperations({ fileCreateOperation('appspec.json', 'test content') })

    But I get the following errors:
    WorkflowScript: 32: Missing required parameter: "fileOperations" @ line 32, column 6.
    fileOperations({ fileCreateOperation('appspec.json', 'test content') })
    ^

    WorkflowScript: 32: Arguments to "fileCreateOperation" must be explicitly named. @ line 32, column 23.
    fileOperations({ fileCreateOperation('appspec.json', 'test content') })
    ^
    I also tried the following:

    fileOperations([ fileCreateOperation('appspec.json', 'test content') ])

    But I get the following error:

    java.lang.IllegalArgumentException: Expected named arguments but got [appspec.json, test content]


    Am I doing something wrong?

    1. I solved the issue by using the following syntax:

      fileOperations([ fileCreateOperation(fileName:'appspec.json', flieContent:'test content') ])

      The documentation for this plugin really needs to be updated: https://github.com/jenkinsci/file-operations-plugin 

  7. I need some help regarding deleting files in Windows.

    I have created a step with the following:

    fileOperations([fileCopyOperation(excludes: '', flattenFiles: true, includes: 'website/app_offline_template.htm', targetLocation: 'C:\\www\\release'), fileRenameOperation(destination: 'C:\\www\\release\\app_offline.htm', source: 'C:\\www\\release\\app_offline_template.htm')])

    fileOperations([fileDeleteOperation(excludes: '', includes: 'C:\\www\\release\\app_offline.htm')])

     

    Step 1 works fine, copies the file and renames is.

    step 2, deleting gives me this error: FATAL: Expecting Ant GLOB pattern, but saw 'C:\www\release\app_offline.htm'. See http://ant.apache.org/manual/Types/fileset.html for syntax

    I have also tried with \\app_offline* and other variations

    1. Even like: 

      FATAL: Expecting Ant GLOB pattern, but saw '/www/release/app_offline.htm'. See...
    2. Current workaround:

      Create folder, move file there, remove folder:

      fileOperations([folderCreateOperation('/www/release/old'), fileRenameOperation(destination: '/www/release/old/app_offline.htm', source: '/www/release/app_offline.htm'), folderDeleteOperation('/www/release/old/')])

      1. Stuck on the same problem and the current example is just wrong. 

        Anyway, thx for the workaround!

  8. How can I use fileOperations like folderCreateOperation in the steps block a declarative pipeline? I have tried implementations using various syntaxes, but I can't get any to work.

    I have also tried using a script block in my declarative pipeline steps block with the scripted examples above and elsewhere. I can't get these to work either. For example when I try:

    steps {

                   script {

                       step([$class: 'FileOperationsBuilder', fileOperations: [[$class: 'folderCreateOperation', folderPath: 'build']]])

                    }

               }

    I get:

    "Required context class hudson.FilePath is missing Perhaps you forgot to surround the code with a step that provides this, such as: node"

    I am not helped by being new to Jenkins and groovy...


    1. stage('Build') {
      	agent {
      		label "foo"
      	}
      	steps {
      		script {
      			fileOperations([
      					fileDownloadOperation(
      							password: '',
      							targetFileName: 'foo.zip',
      							targetLocation: "${WORKSPACE}",
      							url: 'https://foobar.com/foo.zip',
      							userName: ''),
      					fileUnZipOperation(
      							filePath: 'foo.zip',
      							targetLocation: '.'),
      					folderCopyOperation(
      							destinationFolderPath: 'dest',
      							sourceFolderPath: 'foo/content'),
      					folderDeleteOperation(
      							'./foo'
      					)
      			])
      		}
      	}
      }
      1. I tried to Use FileOperations in my Jenkinsfile but still facing same error, is there any prerequisite to use this plugin


        stage("FileOperation") {
        steps {
        script {
        fileOperations([
        folderCreateOperation(
        folderPath:"${env.WORKSPACE}/test_plugin"
        )
        ])
        }
        }
        }

        1. As written in my example above, you should use just ${WORKSPACE} instead of ${env.WORKSPACE} because it's not an environment variable. I'm using it this way and it works like a charm:

          fileOperations([
          folderRenameOperation(
          source: "${WORKSPACE}/bin",
          destination: "${WORKSPACE}/delivery"
              ),
          folderCreateOperation(
          folderPath: "${WORKSPACE}/old"
              )
          ])
          1. Thanks Yves,

            It worked fine for me, one  more query I have. How I could have multile value of 

            folderPath: value1 value2 ... value2


            Thanks in advance

  9. i cant rename file or folder on windows system and use with dir also cant rename


    [Pipeline] echo
    D:/Program/ETL/[Deploy]DataCenter_20181120_152313_ed9c470/DataCenter/.profile/.profile
    [Pipeline] echo
    D:/Program/ETL/[Deploy]DataCenter_20181120_152313_ed9c470/DataCenter/.profile/prod.profile
    [Pipeline] dir
    Running in D:/Program/ETL/[Deploy]DataCenter_20181120_152313_ed9c470/DataCenter/.profile
    [Pipeline] {
    [Pipeline] step
    File Rename Operation:
    FATAL: null
    null
    FATAL: null


  10. I confirm that fileRenameOperation does not work for me too. And I think there is a critical problem.
    Ok, my source and destination are not in the Workspace. But:

    • I think it should not be limited to files in Workspace
    • The error message should give more explanations
    • And  most important !
      It should either not work at all if not on the workspace or do what it is expected to do.

      Currently, working on files and folders outside the directory, if the destination is a file name, it fails. But if the destination is a directory, it silently remove the directory and replace it with a file !!!