#677  Build steps pass regardless of command exit code
Closed
John opened 2 years ago

Relevant step in YAML:

- name: lint-template
  steps:
  - !CheckoutStep
    name: checkout
    cloneCredential: !DefaultCredential {}
    withLfs: false
    withSubmodules: false
    condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
  - !CommandStep
    name: lint
    runInContainer: true
    image: acme/linter:latest
    interpreter: !DefaultInterpreter
      commands:
      - set -e
      - find . -maxdepth 2 -type f -name '*.sh' -exec shellcheck {} \;
      - find . -maxdepth 2 -type f -name '*.yml' -name '*.yaml' -exec yamllint {} \;
      - find . -maxdepth 2 -type f -name 'Dockerfile' -exec hadolint {} \;
      - find . -maxdepth 2 -type f -name '*.py' -exec black --check --diff {} \;
      - find . -maxdepth 2 -type f -name '*.py' -exec pylint -d missing-docstring,import-error,no-self-use,bad-continuation {} \;
    useTTY: true
    condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL

Imported into another project via Import:

version: 15
imports:
- projectPath: acme/linter
  tag: v6

Lint step being run:

12:01:09 Running step "build -> lint"...
12:01:10 --- test.py	2022-04-13 17:01:09.016417 +0000
12:01:10 +++ test.py	2022-04-13 17:01:10.082367 +0000
12:01:10 @@ -37,11 +37,13 @@
12:01:10      '/bin/test"@FILENAME@" --format "@FORMAT@" '
12:01:10      + "--db @MEDIA_DB@ @FILTER@ -non-strict -rename "
12:01:10      + "--action move --conflict override --log-file /tmp/test.log"
12:01:10  )
12:01:10  
12:01:10 -TEST_TOKEN = Path("/etc/k8s/secret/TEST_TOKEN").read_text(encoding="utf-8").rstrip()
12:01:10 +TEST_TOKEN = (
12:01:10 +    Path("/etc/k8s/secret/TEST_TOKEN").read_text(encoding="utf-8").rstrip()
12:01:10 +)
12:01:10 would reformat test.py
12:01:10
12:01:10 Oh no! ?? ?? ??
12:01:10 1 file would be reformatted.
12:01:12 ************* Module test
12:01:12 test.py:194:16: W0621: Redefining name 'err' from outer scope (line 172) (redefined-outer-name)
12:01:12
12:01:12 -----------------------------------
12:01:12 Your code has been rated at 9.94/10
12:01:12
12:01:12
12:01:12 Step "build -> lint" is successful

But running the lint command on the command line show the exit code is non-zero:

/ # black --check --diff test.py
--- test.py     2022-04-13 18:29:39.922655 +0000
+++ test.py     2022-04-13 18:30:24.439172 +0000
@@ -37,11 +37,13 @@
     '/bin/test"@FILENAME@" --format "@FORMAT@" '
     + "--db @MEDIA_DB@ @FILTER@ -non-strict -rename "
     + "--action move --conflict override --log-file /tmp/test.log"
 )

-TEST_TOKEN = Path("/etc/k8s/secret/TEST_TOKEN").read_text(encoding="utf-8").rstrip()
+TEST_TOKEN = (
+    Path("/etc/k8s/secret/TEST_TOKEN").read_text(encoding="utf-8").rstrip()
+)
-
would reformat test.py

Oh no! ?? ?? ??
1 file would be reformatted.
/ # echo $?
1

Any idea on whats making the lint step always pass regardless of any of the commands exiting with a non-zero exit code?

Also as a side note, trying to view .onedev-buildspec.yml file in a project that just contains an import from another project fails with an HTTP 500

Robin Shen commented 2 years ago

Please wrap your command with a shell script, and run the shell script on your terminal to see if it exits with non-zero code.

Or you may create example projects here (code.onedev.io) which I can run to reproduce the issue.

Robin Shen commented 2 years ago

Also for 500 error when view .onedev-buildspec.yml, I tried but it works at my side. Please show me detailed reproducing steps.

John commented 2 years ago

Thanks for the sanity check, looks like the {} \; part of the find command was throwing off the exit code, swapping to {} \+ resolved my issue. I'll create a separate issue for the HTTP 500 code since its not directly related. Thanks!

John changed state to 'Closed' 2 years ago
Previous Value Current Value
Open
Closed
John commented 2 years ago

closed

issue 1 of 1
Type
Bug
Priority
Normal
Assignee
Affected Versions
Not Found
Issue Votes (0)
Watchers (4)
Reference
onedev/server#677
Please wait...
Page is in error, reload to recover