# How to make job failed with xcopy

**URL:** <https://community.jenkins.io/t/how-to-make-job-failed-with-xcopy/5290>\
**Category:** Using Jenkins\
**Created:** [January 11, 2023, 11:45am UTC](https://community.jenkins.io/t/how-to-make-job-failed-with-xcopy/5290 "2023-01-11T11:45:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocketfingers](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/rocketfingers/32/3118_2.png) [@rocketfingers](https://community.jenkins.io/u/rocketfingers)\
**Post date:** [January 11, 2023, 11:45am UTC](https://community.jenkins.io/t/how-to-make-job-failed-with-xcopy/5290/1 "2023-01-11T11:45:21Z")

</div>

Hi,

we execute Windows batch command and we use xcopy to copy web.config file"

set webconfig=C:\Program Files (x86)\Jenkins\customWorkspace\Staging\Configs\Sky24SPA\web.config  
@REM Get proper config  
xcopy “%webconfig%” “%backendBuildDir%” /y

but when the file doesn’t exist we want build to be failed. Normallny withoud /c parameter xcopy throws error code , but Jenkins doesn’t use this error and goes furher with the build.  
After file doesn’t exist we want build to end.

Could you help?

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [January 11, 2023, 12:43pm UTC](https://community.jenkins.io/t/how-to-make-job-failed-with-xcopy/5290/2 "2023-01-11T12:43:42Z")

</div>

You have any other commands inside the batch file after the xcopy command?  
If yes you will need to check the errorlevel inside an if statement and properly exit the batch script if it is not the right value.  
Windows batch script are never stopped once a command returns a non zero exit code contrary to bash script where you can enable such a behavior (Jenkins enables it by default, but it can be overridden inside a script)

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [January 11, 2023, 2:03pm UTC](https://community.jenkins.io/t/how-to-make-job-failed-with-xcopy/5290/3 "2023-01-11T14:03:53Z")

</div>

Check out the information here, it provides a good overview and information. [How do I make a batch file terminate upon encountering an error? - Stack Overflow](https://stackoverflow.com/questions/734598/how-do-i-make-a-batch-file-terminate-upon-encountering-an-error)
