How to error trap in Jenkins Execute shell?











up vote
2
down vote

favorite
1












I am running a bunch of git operations in execute shell Jenkins configurations. I do see the error being generated, but Jenkins job still shows up as successful. How do I trap the error below so it fails the status of Jenkins job:



error: failed to push some refs to 'ssh://git@git



After editing jenkins shell git push to look like this:



git push "$target" --all | grep -z "error:" && exit 1



Jenkins job is still marked successful even though the error is occuring



15:24:06  ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
15:24:06 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
15:24:06 hint: Updates were rejected because the remote contains work that you do
15:24:06 hint: not have locally. This is usually caused by another repository pushing
15:24:06 hint: to the same ref. You may want to first integrate the remote changes
15:24:06 hint: (e.g., 'git pull ...') before pushing again.
15:24:06 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
15:24:06 Everything up-to-date
15:24:07 Finished: SUCCESS


EDIT #2 All the changes exist in Execute shell (#!/bin/bash) configuration part of jenkins.



Script:



RESPONSE=$(git push "$target" --all | grep "error:" || true)


if [ -n "$RESPONSE" ]; then
exit 1
fi


Output:



14:42:30 Cloning into bare repository 'testing-repo.git'...
14:44:25 From bitbucket.org:TEST/testing-repo
14:44:25 * branch HEAD -> FETCH_HEAD
14:44:29 remote:
14:44:29 ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
14:44:29 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
14:44:29 hint: Updates were rejected because the remote contains work that you do
14:44:29 hint: not have locally. This is usually caused by another repository pushing
14:44:29 hint: to the same ref. You may want to first integrate the remote changes
14:44:29 hint: (e.g., 'git pull ...') before pushing again.
14:44:29 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
14:44:29 Everything up-to-date
14:44:29 Finished: SUCCESS


EDIT #3: Actually when I am debugging in the shell $RESPONSE doesn't contain any data, so it would explain why it doesn't change the status of the jenkins job. So it seems even if git command actually did what it is supposed to, it did not feed output of the command into $RESPONSE



EDIT #4 RESPONSE=$(git push "$target" --all 2>&1 | grep "error:" || true) did the trick.










share|improve this question




























    up vote
    2
    down vote

    favorite
    1












    I am running a bunch of git operations in execute shell Jenkins configurations. I do see the error being generated, but Jenkins job still shows up as successful. How do I trap the error below so it fails the status of Jenkins job:



    error: failed to push some refs to 'ssh://git@git



    After editing jenkins shell git push to look like this:



    git push "$target" --all | grep -z "error:" && exit 1



    Jenkins job is still marked successful even though the error is occuring



    15:24:06  ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
    15:24:06 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
    15:24:06 hint: Updates were rejected because the remote contains work that you do
    15:24:06 hint: not have locally. This is usually caused by another repository pushing
    15:24:06 hint: to the same ref. You may want to first integrate the remote changes
    15:24:06 hint: (e.g., 'git pull ...') before pushing again.
    15:24:06 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    15:24:06 Everything up-to-date
    15:24:07 Finished: SUCCESS


    EDIT #2 All the changes exist in Execute shell (#!/bin/bash) configuration part of jenkins.



    Script:



    RESPONSE=$(git push "$target" --all | grep "error:" || true)


    if [ -n "$RESPONSE" ]; then
    exit 1
    fi


    Output:



    14:42:30 Cloning into bare repository 'testing-repo.git'...
    14:44:25 From bitbucket.org:TEST/testing-repo
    14:44:25 * branch HEAD -> FETCH_HEAD
    14:44:29 remote:
    14:44:29 ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
    14:44:29 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
    14:44:29 hint: Updates were rejected because the remote contains work that you do
    14:44:29 hint: not have locally. This is usually caused by another repository pushing
    14:44:29 hint: to the same ref. You may want to first integrate the remote changes
    14:44:29 hint: (e.g., 'git pull ...') before pushing again.
    14:44:29 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    14:44:29 Everything up-to-date
    14:44:29 Finished: SUCCESS


    EDIT #3: Actually when I am debugging in the shell $RESPONSE doesn't contain any data, so it would explain why it doesn't change the status of the jenkins job. So it seems even if git command actually did what it is supposed to, it did not feed output of the command into $RESPONSE



    EDIT #4 RESPONSE=$(git push "$target" --all 2>&1 | grep "error:" || true) did the trick.










    share|improve this question


























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      I am running a bunch of git operations in execute shell Jenkins configurations. I do see the error being generated, but Jenkins job still shows up as successful. How do I trap the error below so it fails the status of Jenkins job:



      error: failed to push some refs to 'ssh://git@git



      After editing jenkins shell git push to look like this:



      git push "$target" --all | grep -z "error:" && exit 1



      Jenkins job is still marked successful even though the error is occuring



      15:24:06  ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
      15:24:06 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
      15:24:06 hint: Updates were rejected because the remote contains work that you do
      15:24:06 hint: not have locally. This is usually caused by another repository pushing
      15:24:06 hint: to the same ref. You may want to first integrate the remote changes
      15:24:06 hint: (e.g., 'git pull ...') before pushing again.
      15:24:06 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
      15:24:06 Everything up-to-date
      15:24:07 Finished: SUCCESS


      EDIT #2 All the changes exist in Execute shell (#!/bin/bash) configuration part of jenkins.



      Script:



      RESPONSE=$(git push "$target" --all | grep "error:" || true)


      if [ -n "$RESPONSE" ]; then
      exit 1
      fi


      Output:



      14:42:30 Cloning into bare repository 'testing-repo.git'...
      14:44:25 From bitbucket.org:TEST/testing-repo
      14:44:25 * branch HEAD -> FETCH_HEAD
      14:44:29 remote:
      14:44:29 ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
      14:44:29 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
      14:44:29 hint: Updates were rejected because the remote contains work that you do
      14:44:29 hint: not have locally. This is usually caused by another repository pushing
      14:44:29 hint: to the same ref. You may want to first integrate the remote changes
      14:44:29 hint: (e.g., 'git pull ...') before pushing again.
      14:44:29 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
      14:44:29 Everything up-to-date
      14:44:29 Finished: SUCCESS


      EDIT #3: Actually when I am debugging in the shell $RESPONSE doesn't contain any data, so it would explain why it doesn't change the status of the jenkins job. So it seems even if git command actually did what it is supposed to, it did not feed output of the command into $RESPONSE



      EDIT #4 RESPONSE=$(git push "$target" --all 2>&1 | grep "error:" || true) did the trick.










      share|improve this question















      I am running a bunch of git operations in execute shell Jenkins configurations. I do see the error being generated, but Jenkins job still shows up as successful. How do I trap the error below so it fails the status of Jenkins job:



      error: failed to push some refs to 'ssh://git@git



      After editing jenkins shell git push to look like this:



      git push "$target" --all | grep -z "error:" && exit 1



      Jenkins job is still marked successful even though the error is occuring



      15:24:06  ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
      15:24:06 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
      15:24:06 hint: Updates were rejected because the remote contains work that you do
      15:24:06 hint: not have locally. This is usually caused by another repository pushing
      15:24:06 hint: to the same ref. You may want to first integrate the remote changes
      15:24:06 hint: (e.g., 'git pull ...') before pushing again.
      15:24:06 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
      15:24:06 Everything up-to-date
      15:24:07 Finished: SUCCESS


      EDIT #2 All the changes exist in Execute shell (#!/bin/bash) configuration part of jenkins.



      Script:



      RESPONSE=$(git push "$target" --all | grep "error:" || true)


      if [ -n "$RESPONSE" ]; then
      exit 1
      fi


      Output:



      14:42:30 Cloning into bare repository 'testing-repo.git'...
      14:44:25 From bitbucket.org:TEST/testing-repo
      14:44:25 * branch HEAD -> FETCH_HEAD
      14:44:29 remote:
      14:44:29 ! [remote rejected] test/test/testBranch ->test/test/testBranch (pre-receive hook declined)
      14:44:29 error: failed to push some refs to 'ssh://git@git.testing-repo/test/test-test.git'
      14:44:29 hint: Updates were rejected because the remote contains work that you do
      14:44:29 hint: not have locally. This is usually caused by another repository pushing
      14:44:29 hint: to the same ref. You may want to first integrate the remote changes
      14:44:29 hint: (e.g., 'git pull ...') before pushing again.
      14:44:29 hint: See the 'Note about fast-forwards' in 'git push --help' for details.
      14:44:29 Everything up-to-date
      14:44:29 Finished: SUCCESS


      EDIT #3: Actually when I am debugging in the shell $RESPONSE doesn't contain any data, so it would explain why it doesn't change the status of the jenkins job. So it seems even if git command actually did what it is supposed to, it did not feed output of the command into $RESPONSE



      EDIT #4 RESPONSE=$(git push "$target" --all 2>&1 | grep "error:" || true) did the trick.







      git shell jenkins error-handling






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 16:20

























      asked Nov 10 at 4:54









      Dzerlig

      846




      846
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          This issue is strange because this git push failed so it should return an exit code different from 0 which then should fail your build. The exit code of last command of the Jenkin's Execute Shell build step is what determines the success/failure of the Build Step. 0 - success, anything else - failure. If you can provide more data maybe I could debug this. What exit code is being returned after your git push? (You can check exit code of last command by typing: echo $?) Can you also add some example?



          But don't worry I also have a simple workaround for you (Maybe not pretty but it works). You can always manually say to Jenkins to fail build by setting error code by yourself. In this case, you can grep your git push for error. If there is, exit with code 1.



          git push ... | grep -z "error: failed to push some refs to" && exit 1 || true


          Or more generic:



           git push ... | grep -z "error:" && exit 1 || true


          Edit



          Where do you exactly run this git push command? In execute shell build step? Do you use Jenkins Source Code Management? (It will make easier to work with repositories inside Jenkins build)



          Dummy job to show that exit 1 will force failure:



          Build Execute shellConsole Output



          you can always try doing the same more bash script like:



          RESPONSE=$(git push ... | grep -z "error:" || true)

          if [ -n "$RESPONSE" ]; then
          exit 1
          fi


          also, I've added || true to workaround commands because I have forgotten that grep will exit 1 if no line is selected:




          Exit status is 0 if any line is selected, 1 otherwise




          Which means that this would force fail all of your builds.






          share|improve this answer























          • Thank you Raoslaw. All I am trying to do is synchronizing 2 repos in jenkins shell between 2 instances of BitBucket. Some of pushes are being rejected due to (pre-receive hook declined) and it generates final error above. Unfortunately it doesn't fail Jenkins job. I just want to have a warning when the push fails by marking Jenkins job failed or unstable. Will try your suggestion. Thanks again.
            – Dzerlig
            Nov 10 at 15:16










          • Modified my question with more information, error still doesn't mark status of Jenkins job as a failure.
            – Dzerlig
            Nov 10 at 15:38










          • @Dzerlig Okay let me check, I'll create dummy job to debug that. By the way, do you use Execute shell build step?
            – Raoslaw Szamszur
            Nov 10 at 17:21










          • @Dzerlig Please look at the edit. Can you add you execute shell to question? Maybe there is something wrong or a typo. And if you want to make build unstable just set in Execute Shell Advanced option Exit code to set build unstable to 1.
            – Raoslaw Szamszur
            Nov 10 at 18:12






          • 1




            Thank you! I got it, Edit #4 :)
            – Dzerlig
            Nov 11 at 16:21











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236096%2fhow-to-error-trap-in-jenkins-execute-shell%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          This issue is strange because this git push failed so it should return an exit code different from 0 which then should fail your build. The exit code of last command of the Jenkin's Execute Shell build step is what determines the success/failure of the Build Step. 0 - success, anything else - failure. If you can provide more data maybe I could debug this. What exit code is being returned after your git push? (You can check exit code of last command by typing: echo $?) Can you also add some example?



          But don't worry I also have a simple workaround for you (Maybe not pretty but it works). You can always manually say to Jenkins to fail build by setting error code by yourself. In this case, you can grep your git push for error. If there is, exit with code 1.



          git push ... | grep -z "error: failed to push some refs to" && exit 1 || true


          Or more generic:



           git push ... | grep -z "error:" && exit 1 || true


          Edit



          Where do you exactly run this git push command? In execute shell build step? Do you use Jenkins Source Code Management? (It will make easier to work with repositories inside Jenkins build)



          Dummy job to show that exit 1 will force failure:



          Build Execute shellConsole Output



          you can always try doing the same more bash script like:



          RESPONSE=$(git push ... | grep -z "error:" || true)

          if [ -n "$RESPONSE" ]; then
          exit 1
          fi


          also, I've added || true to workaround commands because I have forgotten that grep will exit 1 if no line is selected:




          Exit status is 0 if any line is selected, 1 otherwise




          Which means that this would force fail all of your builds.






          share|improve this answer























          • Thank you Raoslaw. All I am trying to do is synchronizing 2 repos in jenkins shell between 2 instances of BitBucket. Some of pushes are being rejected due to (pre-receive hook declined) and it generates final error above. Unfortunately it doesn't fail Jenkins job. I just want to have a warning when the push fails by marking Jenkins job failed or unstable. Will try your suggestion. Thanks again.
            – Dzerlig
            Nov 10 at 15:16










          • Modified my question with more information, error still doesn't mark status of Jenkins job as a failure.
            – Dzerlig
            Nov 10 at 15:38










          • @Dzerlig Okay let me check, I'll create dummy job to debug that. By the way, do you use Execute shell build step?
            – Raoslaw Szamszur
            Nov 10 at 17:21










          • @Dzerlig Please look at the edit. Can you add you execute shell to question? Maybe there is something wrong or a typo. And if you want to make build unstable just set in Execute Shell Advanced option Exit code to set build unstable to 1.
            – Raoslaw Szamszur
            Nov 10 at 18:12






          • 1




            Thank you! I got it, Edit #4 :)
            – Dzerlig
            Nov 11 at 16:21















          up vote
          2
          down vote



          accepted










          This issue is strange because this git push failed so it should return an exit code different from 0 which then should fail your build. The exit code of last command of the Jenkin's Execute Shell build step is what determines the success/failure of the Build Step. 0 - success, anything else - failure. If you can provide more data maybe I could debug this. What exit code is being returned after your git push? (You can check exit code of last command by typing: echo $?) Can you also add some example?



          But don't worry I also have a simple workaround for you (Maybe not pretty but it works). You can always manually say to Jenkins to fail build by setting error code by yourself. In this case, you can grep your git push for error. If there is, exit with code 1.



          git push ... | grep -z "error: failed to push some refs to" && exit 1 || true


          Or more generic:



           git push ... | grep -z "error:" && exit 1 || true


          Edit



          Where do you exactly run this git push command? In execute shell build step? Do you use Jenkins Source Code Management? (It will make easier to work with repositories inside Jenkins build)



          Dummy job to show that exit 1 will force failure:



          Build Execute shellConsole Output



          you can always try doing the same more bash script like:



          RESPONSE=$(git push ... | grep -z "error:" || true)

          if [ -n "$RESPONSE" ]; then
          exit 1
          fi


          also, I've added || true to workaround commands because I have forgotten that grep will exit 1 if no line is selected:




          Exit status is 0 if any line is selected, 1 otherwise




          Which means that this would force fail all of your builds.






          share|improve this answer























          • Thank you Raoslaw. All I am trying to do is synchronizing 2 repos in jenkins shell between 2 instances of BitBucket. Some of pushes are being rejected due to (pre-receive hook declined) and it generates final error above. Unfortunately it doesn't fail Jenkins job. I just want to have a warning when the push fails by marking Jenkins job failed or unstable. Will try your suggestion. Thanks again.
            – Dzerlig
            Nov 10 at 15:16










          • Modified my question with more information, error still doesn't mark status of Jenkins job as a failure.
            – Dzerlig
            Nov 10 at 15:38










          • @Dzerlig Okay let me check, I'll create dummy job to debug that. By the way, do you use Execute shell build step?
            – Raoslaw Szamszur
            Nov 10 at 17:21










          • @Dzerlig Please look at the edit. Can you add you execute shell to question? Maybe there is something wrong or a typo. And if you want to make build unstable just set in Execute Shell Advanced option Exit code to set build unstable to 1.
            – Raoslaw Szamszur
            Nov 10 at 18:12






          • 1




            Thank you! I got it, Edit #4 :)
            – Dzerlig
            Nov 11 at 16:21













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          This issue is strange because this git push failed so it should return an exit code different from 0 which then should fail your build. The exit code of last command of the Jenkin's Execute Shell build step is what determines the success/failure of the Build Step. 0 - success, anything else - failure. If you can provide more data maybe I could debug this. What exit code is being returned after your git push? (You can check exit code of last command by typing: echo $?) Can you also add some example?



          But don't worry I also have a simple workaround for you (Maybe not pretty but it works). You can always manually say to Jenkins to fail build by setting error code by yourself. In this case, you can grep your git push for error. If there is, exit with code 1.



          git push ... | grep -z "error: failed to push some refs to" && exit 1 || true


          Or more generic:



           git push ... | grep -z "error:" && exit 1 || true


          Edit



          Where do you exactly run this git push command? In execute shell build step? Do you use Jenkins Source Code Management? (It will make easier to work with repositories inside Jenkins build)



          Dummy job to show that exit 1 will force failure:



          Build Execute shellConsole Output



          you can always try doing the same more bash script like:



          RESPONSE=$(git push ... | grep -z "error:" || true)

          if [ -n "$RESPONSE" ]; then
          exit 1
          fi


          also, I've added || true to workaround commands because I have forgotten that grep will exit 1 if no line is selected:




          Exit status is 0 if any line is selected, 1 otherwise




          Which means that this would force fail all of your builds.






          share|improve this answer














          This issue is strange because this git push failed so it should return an exit code different from 0 which then should fail your build. The exit code of last command of the Jenkin's Execute Shell build step is what determines the success/failure of the Build Step. 0 - success, anything else - failure. If you can provide more data maybe I could debug this. What exit code is being returned after your git push? (You can check exit code of last command by typing: echo $?) Can you also add some example?



          But don't worry I also have a simple workaround for you (Maybe not pretty but it works). You can always manually say to Jenkins to fail build by setting error code by yourself. In this case, you can grep your git push for error. If there is, exit with code 1.



          git push ... | grep -z "error: failed to push some refs to" && exit 1 || true


          Or more generic:



           git push ... | grep -z "error:" && exit 1 || true


          Edit



          Where do you exactly run this git push command? In execute shell build step? Do you use Jenkins Source Code Management? (It will make easier to work with repositories inside Jenkins build)



          Dummy job to show that exit 1 will force failure:



          Build Execute shellConsole Output



          you can always try doing the same more bash script like:



          RESPONSE=$(git push ... | grep -z "error:" || true)

          if [ -n "$RESPONSE" ]; then
          exit 1
          fi


          also, I've added || true to workaround commands because I have forgotten that grep will exit 1 if no line is selected:




          Exit status is 0 if any line is selected, 1 otherwise




          Which means that this would force fail all of your builds.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 15:45

























          answered Nov 10 at 11:58









          Raoslaw Szamszur

          895415




          895415












          • Thank you Raoslaw. All I am trying to do is synchronizing 2 repos in jenkins shell between 2 instances of BitBucket. Some of pushes are being rejected due to (pre-receive hook declined) and it generates final error above. Unfortunately it doesn't fail Jenkins job. I just want to have a warning when the push fails by marking Jenkins job failed or unstable. Will try your suggestion. Thanks again.
            – Dzerlig
            Nov 10 at 15:16










          • Modified my question with more information, error still doesn't mark status of Jenkins job as a failure.
            – Dzerlig
            Nov 10 at 15:38










          • @Dzerlig Okay let me check, I'll create dummy job to debug that. By the way, do you use Execute shell build step?
            – Raoslaw Szamszur
            Nov 10 at 17:21










          • @Dzerlig Please look at the edit. Can you add you execute shell to question? Maybe there is something wrong or a typo. And if you want to make build unstable just set in Execute Shell Advanced option Exit code to set build unstable to 1.
            – Raoslaw Szamszur
            Nov 10 at 18:12






          • 1




            Thank you! I got it, Edit #4 :)
            – Dzerlig
            Nov 11 at 16:21


















          • Thank you Raoslaw. All I am trying to do is synchronizing 2 repos in jenkins shell between 2 instances of BitBucket. Some of pushes are being rejected due to (pre-receive hook declined) and it generates final error above. Unfortunately it doesn't fail Jenkins job. I just want to have a warning when the push fails by marking Jenkins job failed or unstable. Will try your suggestion. Thanks again.
            – Dzerlig
            Nov 10 at 15:16










          • Modified my question with more information, error still doesn't mark status of Jenkins job as a failure.
            – Dzerlig
            Nov 10 at 15:38










          • @Dzerlig Okay let me check, I'll create dummy job to debug that. By the way, do you use Execute shell build step?
            – Raoslaw Szamszur
            Nov 10 at 17:21










          • @Dzerlig Please look at the edit. Can you add you execute shell to question? Maybe there is something wrong or a typo. And if you want to make build unstable just set in Execute Shell Advanced option Exit code to set build unstable to 1.
            – Raoslaw Szamszur
            Nov 10 at 18:12






          • 1




            Thank you! I got it, Edit #4 :)
            – Dzerlig
            Nov 11 at 16:21
















          Thank you Raoslaw. All I am trying to do is synchronizing 2 repos in jenkins shell between 2 instances of BitBucket. Some of pushes are being rejected due to (pre-receive hook declined) and it generates final error above. Unfortunately it doesn't fail Jenkins job. I just want to have a warning when the push fails by marking Jenkins job failed or unstable. Will try your suggestion. Thanks again.
          – Dzerlig
          Nov 10 at 15:16




          Thank you Raoslaw. All I am trying to do is synchronizing 2 repos in jenkins shell between 2 instances of BitBucket. Some of pushes are being rejected due to (pre-receive hook declined) and it generates final error above. Unfortunately it doesn't fail Jenkins job. I just want to have a warning when the push fails by marking Jenkins job failed or unstable. Will try your suggestion. Thanks again.
          – Dzerlig
          Nov 10 at 15:16












          Modified my question with more information, error still doesn't mark status of Jenkins job as a failure.
          – Dzerlig
          Nov 10 at 15:38




          Modified my question with more information, error still doesn't mark status of Jenkins job as a failure.
          – Dzerlig
          Nov 10 at 15:38












          @Dzerlig Okay let me check, I'll create dummy job to debug that. By the way, do you use Execute shell build step?
          – Raoslaw Szamszur
          Nov 10 at 17:21




          @Dzerlig Okay let me check, I'll create dummy job to debug that. By the way, do you use Execute shell build step?
          – Raoslaw Szamszur
          Nov 10 at 17:21












          @Dzerlig Please look at the edit. Can you add you execute shell to question? Maybe there is something wrong or a typo. And if you want to make build unstable just set in Execute Shell Advanced option Exit code to set build unstable to 1.
          – Raoslaw Szamszur
          Nov 10 at 18:12




          @Dzerlig Please look at the edit. Can you add you execute shell to question? Maybe there is something wrong or a typo. And if you want to make build unstable just set in Execute Shell Advanced option Exit code to set build unstable to 1.
          – Raoslaw Szamszur
          Nov 10 at 18:12




          1




          1




          Thank you! I got it, Edit #4 :)
          – Dzerlig
          Nov 11 at 16:21




          Thank you! I got it, Edit #4 :)
          – Dzerlig
          Nov 11 at 16:21


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236096%2fhow-to-error-trap-in-jenkins-execute-shell%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini