1

I have to make a change to an existing Jenkins pipeline. I need to rename the file to incorporate the version. The version is already being used in other portions of the script.

This is what I have found but rename-item is not recognized as a command. Where can i find the commands I can use? How to I make this work?

stage('Rename') {
    bat """
        rename-item -Path "C:\\temp\\OriginalName.exe" -NewName "OriginalName-${version}.exe"
    """
} 

TIA

Jeff
  • 2,061
  • 4
  • 27
  • 45
  • Have you tried with `powershell` instead of `bat`? – Melkjot Oct 14 '21 at 14:13
  • You can use the `fileRenameOperation` in the [File Operations Plugin](https://www.jenkins.io/doc/pipeline/steps/file-operations/) to achieve this easily (cross platform). – Noam Helmer Oct 14 '21 at 14:16
  • I see that file operations plug in is installed but I dont know the syntax to use in this simple case – Jeff Oct 14 '21 at 14:17
  • Melkjot - that worked. One more question - How can I embed a variable into a string? I am passing a param into the next step as :C:\\Temp\originalName-${version}.exe" but it is being taken literally – Jeff Oct 14 '21 at 14:25
  • Basically try a single quote instead of double quotes for the outer code block. like this: bat ''' rename-item -Path "C:\\temp\\OriginalName.exe" -NewName "OriginalName-${version}.exe" ''' – Kaus2b Oct 14 '21 at 14:47
  • see this answer on how to run powershell commands in the pipeline. I would include the function in a class in src : https://stackoverflow.com/questions/42436370/executing-powershell-command-directly-in-jenkins-pipeline or use powershell(". '.Test.ps1'") from version 2.28 – TudorIftimie Oct 14 '21 at 16:17

0 Answers0