openshift-eng / aos-cd-jobs

Apache License 2.0
48 stars 144 forks source link

sjb: +o errexit is not respected in host scripts #247

Closed 0xmichalis closed 7 years ago

0xmichalis commented 7 years ago

https://ci.openshift.redhat.com/jenkins/view/All/job/ami_build_origin_int_rhel_fork/16/consoleFull#-206914687858b6e51eb7608a5981914356

########## STARTING STAGE: MAKE A TRELLO COMMENT ##########
+ [[ -s /var/lib/jenkins/jobs/ami_build_origin_int_rhel_fork/workspace/activate ]]
+ source /var/lib/jenkins/jobs/ami_build_origin_int_rhel_fork/workspace/activate
++ export VIRTUAL_ENV=/var/lib/jenkins/origin-ci-tool/b58d70e4ba8547fb716da04deb467ce17ccf4345
++ VIRTUAL_ENV=/var/lib/jenkins/origin-ci-tool/b58d70e4ba8547fb716da04deb467ce17ccf4345
++ export PATH=/var/lib/jenkins/origin-ci-tool/b58d70e4ba8547fb716da04deb467ce17ccf4345/bin:/sbin:/usr/sbin:/bin:/usr/bin
++ PATH=/var/lib/jenkins/origin-ci-tool/b58d70e4ba8547fb716da04deb467ce17ccf4345/bin:/sbin:/usr/sbin:/bin:/usr/bin
++ unset PYTHON_HOME
++ export OCT_CONFIG_HOME=/var/lib/jenkins/jobs/ami_build_origin_int_rhel_fork/workspace/.config
++ OCT_CONFIG_HOME=/var/lib/jenkins/jobs/ami_build_origin_int_rhel_fork/workspace/.config
+ set +o nounset +o errexit
+ [[ -n <none> ]]
+ trello comment 'A fork ami has been created for this card: `_16`' --card-url '<none>'
++ export status=FAILURE
++ status=FAILURE
+ set +o xtrace
########## FINISHED STAGE: FAILURE: MAKE A TRELLO COMMENT ##########

cc: @stevekuznetsov

0xmichalis commented 7 years ago

Also, in the same job, a non-zero exit code of a command does not result in failing the stage:

Checking out files:  99% (18738/18927)   
Checking out files: 100% (18927/18927)   
Checking out files: 100% (18927/18927), done.
mv: cannot move ‘origin’ to a subdirectory of itself, ‘origin/origin’
/data/src/github.com/openshift/origin /data/src/github.com/openshift ~
Branch fix-negative-unavailable-replicas set up to track remote branch fix-negative-unavailable-replicas from origin.
Switched to a new branch 'fix-negative-unavailable-replicas'
+ set +o xtrace
########## FINISHED STAGE: SUCCESS: PREPARE REPOSITORIES ##########
stevekuznetsov commented 7 years ago

Re: the first thing -- not super interested in making that work as it's bad practice anyway. I understand it will make porting the fork_ami stuff harder, but I think that is OK.

Re: the second thing -- do you have a reproducer?

0xmichalis commented 7 years ago

@stevekuznetsov what is the suggested way to execute stages that shouldn't fail the job once they fail because we don't really care, eg. a Trello comment? Should we support the intent in the sjb syntax?

Re: the second thing -- do you have a reproducer?

I just realized that the error was hit inside the command I run over ssh.

stevekuznetsov commented 7 years ago

what is the suggested way to execute stages that shouldn't fail the job once they fail because we don't really care, eg. a Trello comment? Should we support the intent in the sjb syntax?

Make the Bash not fail -- for example:

if ! trello_comment ...; then
    echo "Oh well"
fi

See also man trap:

       trap [-lp] [[arg] sigspec ...]
              If a sigspec is ERR, the command arg is executed whenever a a pipeline (which may consist of a single simple command), a list, or
              a  compound  command  returns  a  non-zero exit status, subject to the following conditions.  The ERR trap is not executed if the
              failed command is part of the command list immediately following a while or until keyword, part of the test in an  if  statement,
              part  of a command executed in a && or || list except the command following the final && or ||, any command in a pipeline but the
              last, or if the command's return value is being inverted using !.  These are the same  conditions  obeyed  by  the  errexit  (-e)
              option.
stevekuznetsov commented 7 years ago

Looks like you were using an old base for your branch, problem should be fixed with 78a0e9c24767d5acf0c5519edc260c5baf5ef2e4 and https://github.com/openshift/aos-cd-jobs/commit/b1d17d59c5b68006fc31c93743d5e532c28ad920

0xmichalis commented 7 years ago

Looks like you were using an old base for your branch, problem should be fixed with 78a0e9c and openshift/aos-cd-jobs@b1d17d5

Unlike, my fork is just lacking the last 2 days of commits. https://github.com/kargakis/aos-cd-jobs/commits/master

stevekuznetsov commented 7 years ago

Sorry, I misread your output -- it was an SSH session you started, not one SJB did. Closing this as it's a user error and not from the framework.