Create a folder in slave node using Jenkins pipeline groovy script



  • I have a Jenkins job which runs on a slave node on another machine, both master and slave run on windows. The slave node is being run as a windows service. The main repository has git submodule included. After checking-out the code for both the main and sub module repositories, I need to create a folder inside of the submodule folder and write a file into it with some basic deployment details like tag, version, etc. Structure is something like this:

    main -> submodule -> {newfolder} -> {newfile}

    I am using the mkdir() to create the folder, but it is not being created. I have also tried the dir() method. But nothing seems to be working. Can anyone help on this:

    1. Do I need to provide elevated permissions set for the windows service used to trigger the slave node?
    2. Do I need to provide permissions at folder level?

    Any other check that I am missing, please help.



  • Issue got resolved with the use of https://www.jenkins.io/doc/pipeline/steps/file-operations/ methods like folderCreateOperation & fileCreateOperation. Example code snippet below:

    def path = "${workspace}\submodule\newFolder"
    fileOperations([folderCreateOperation(folderPath: path)])
    dir(path) {
        fileOperations([fileCreateOperation(fileName: 'newFile.properties', fileContent: 'Git_Tag=${env.Git_Tag}')])
    }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2