0

I am trying to execute a window batch command in Jenkins, and it is not working. I have reviewed Run batch command in jenkins, but I couldn't fix from that post.

I ran the following command to copy a file to a new location and give it a new name:

copy /B "%my_home%\base\dist\proj*.war" "%my_home%\base\dist\wars\proj.war"

In my case, the source directory has a single file called proj123.war. The file is successfully copied the the target directory, but the name remains proj123.war rather than renaming to proj.war.

Any idea what I might be doing wrong? Thanks for any help!

Community
  • 1
  • 1
Tim Clotworthy
  • 95
  • 2
  • 11

1 Answers1

0

For 1) Your statement doesn't make any sense.

copy /B "%my_home%\base\dist\proj*.war" "%my_home%\base\dist\wars\proj*.war"

Say you have

projA.war projB.war projC.war

They will all get saved as proj.war, first A, then B, then C. So it will be over written. They won't get copied as individual files.

You also don't need the /B.

In the future, provide a detailed description of the error you're getting.

EDIT: Given the update the comment, the desired command would be.

copy /B "%my_home%\base\dist\proj*.war" "%my_home%\base\dist\wars"

This will copy all files that match proj*.war to the wars directory while keeping the original names.

JordanGS
  • 3,966
  • 5
  • 16
  • 21
  • Although I agree with your statement, this is not an answer – Rik Nov 05 '16 at 19:59
  • @Rik while i agree with your sentiment, i recently joined the community and i would have preferred to post a comment but i am unable to. So i created an answer in an attempt to get more information so i could try to help :) and i even explained how the copy works. He stated that the command worked fine on windows but it shouldn't have as he provided. – JordanGS Nov 05 '16 at 20:06
  • I apologize for the delay. Also, JordanGS is correct my example was in error. It should have read: copy /B "%my_home%\base\dist\proj*.war" "%my_home%\base\dist\wars\proj.war". The result is that the original file called "%my_home%\base\dist\proj123.war" is successfully copied to the target directory, BUT the name remains "proj123.war" rather than the desired "proj.war" (I have edited the post accordingly). – Tim Clotworthy Nov 08 '16 at 15:55
  • @TimClotworthy see update, if this has answered your question please flag it as the correct answer and upvote. If it does not please feel free to comment/clarify the issue :) – JordanGS Nov 08 '16 at 17:27
  • @TimClotworthy You're not changing the source name, you're creating a copy to `destination` with the name `proj.war`. If you want to rename the source file then you have to copy to the same directory and not a different one. – JordanGS Nov 08 '16 at 17:30
  • thanks for the response JordanGS but as originally said I am trying to "copy a file to a new location and give it a new name". I am not trying to rename a source file. YOu can absolutely copy to a new directory with a new name from a windows shell. It works fine in a windows shell. Its not working within the context of Jenkins is the problem. Thanks again. – Tim Clotworthy Nov 08 '16 at 17:42
  • What's the error from the `console` output? This works fine for me. What's your jenkins environment. Master alone or a master-slave? need more information to diagnose. – JordanGS Nov 08 '16 at 17:48
  • I am required to obfuscate the output slightly, but it is essentially: "..\base\dist\wars\proj123.war 1 file(s) copied." In other words, correct target folder, incorrect target name. – Tim Clotworthy Nov 08 '16 at 19:34