Skip to content

Conversation

@davidh44
Copy link
Contributor

@davidh44 davidh44 commented Nov 3, 2025

Motivation and Context

In multi line commands, a subsequent successful command will mask a previous command that fails
Re-adding previous PR that was reverted due to integ test failures - #6524

Modifications

Add set -e to beginning of multi line commands in buildpsecs

@davidh44 davidh44 requested a review from a team as a code owner November 3, 2025 22:57
- echo $MAVEN_OPTIONS
- |
if [ "$JAVA_VERSION" -ge "9" ]; then
set -e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have we not done set -e as soon as we called | as in

      - |
        set -e
        if [ "$JAVA_VERSION" -ge "9" ]; then
          cd test/module-path-tests
          mvn package
          mvn exec:exec -P mock-tests
        fi

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check in if clause won't throw error, we don't need set -e if its false

Copy link
Contributor

@joviegas joviegas Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran a test below

version: 0.2

phases:
  build:
    commands:
      - echo "Test with JAVA_VERSION somehow set incorrectly "
      - export JAVA_VERSION=11.232
      - |
        if [ "JAVA_VERSION" -ge "9" ]; then
          set -e
          echo "Entering the if block"
          cd /nonexistent/directory
          echo "You will not see this"
        fi
      - echo "Build succeded even when if clause failed"

And the Build succeeded even though it gave a log as below

/codebuild/output/tmp/script.sh: line 4: [: JAVA_VERSION: integer expression expected
Build succeded even when if clause failed

I think currently we are assumming the If clause will always pass , there can be issues if the condition in if itself has some typos as I gave example

Inorder to make solution applicable to all the statements after | I think we need to add set -e as soon as we call |
This will also help us to to avoid any issues if we add else part or another if in future. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need it, but can move it up as it is harmless. JAVA_VERSION should never be null, and we don't currently have an else clause. The set e as is will apply to both mvn commands

We'll need to add set e for each separate multiline block that we add in the future

@davidh44 davidh44 enabled auto-merge November 4, 2025 21:33
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 4, 2025

@davidh44 davidh44 added this pull request to the merge queue Nov 4, 2025
Merged via the queue into master with commit 01cc5a5 Nov 4, 2025
46 of 47 checks passed
@github-actions
Copy link

github-actions bot commented Nov 4, 2025

This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2025
@davidh44 davidh44 deleted the hdavidh/buildspecs-sete branch November 4, 2025 23:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants