Option for not printing script lines to job log

Description

Currently, the runners print every line of the script defined in the configuration YAML to the console. However, this quickly pollutes the log, especially if some of your commands are solely to format output.

The yaml:

script:
  - echo --------------------------
  - echo Building ${CI_COMMIT_SHA}
  - echo --------------------------

produces the output

$ echo --------------------------
--------------------------
$ echo Building ${CI_COMMIT_SHA}
Building d358018f1bbf4be787f8cf663ade0865ce3141cd
$ echo --------------------------
--------------------------

If you concatenate all commands to a single line, this looks better but a) still it pollutes the logfile and b) if the formatting gets more complicated (string substitutions, reading files, ...) the single line gets really hard to maintain

The yaml:

script:
  - echo -------------------------- && echo Building ${CI_COMMIT_SHA} && echo --------------------------

produces this output

$ echo -------------------------- && echo Building ${CI_COMMIT_SHA} && echo --------------------------
--------------------------
Building d358018f1bbf4be787f8cf663ade0865ce3141cd
--------------------------

Proposal

An option to disable printing of the CI script lines (the ones beginning with $ )

  • either for the whole script block. Maybe a new member for configuring the log output?
    myjob:
      log:
        suppressStatements: true
    script:
      - echo --------------------------
      - echo Building ${CI_COMMIT_SHA}
      - echo --------------------------
  • or configurable per line - although I don't have a good yaml syntax proposal for this yet. Maybe
    myjob:
      log:
        suppressStatements: true
    script:
      - [suppress, echo --------------------------]
      - [suppress, echo Building ${CI_COMMIT_SHA}]
      - [suppress, echo --------------------------]

Real-world example

The above scripts are simplified to explain the problem. This is a full real-world example of a job which inspects the commit messages for a certain patterns and stop words:

  script:
    - range="origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..${CI_COMMIT_SHORT_SHA}"
    - echo "Inspecting ${range}"
    # Without fetching, the remote branch is not available
    - git fetch --depth=${GIT_DEPTH} origin ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
    # Check that each message begins with at least one [tag]
    - messageWithoutTags=$(git rev-list -E --invert-grep --grep '^((Merge branch .+)|(Merge remote-tracking branch .+)|(Accumulated commit of .+)|(Revert .?)|(\[([A-z0-9])+\].{5,}))' "${range}")
    - "[ -z \"$messageWithoutTags\" ] || (echo -e \"ERROR: The following commit messages don't follow the [tag] pattern:\\n$(echo \"${messageWithoutTags}\" | xargs -n1 git log --format=%s -n 1)\" && exit 1)"
    - echo "----- Commit messages are okay -----"
    # Check that no stop-words are present
    - stopWords="NO COMMIT\|NO MERGE\|NOCOMMIT\|NOMERGE"
    - linesContainingStopWords=$( (git diff -p -M ${range} -- . ':!.gitlab-ci.yml' | ./showlinenum.awk show_path=1 | grep -E '^.+[0-9]+:\+' | grep "${stopWords}" ) || echo "")
    - "[ -z \"$linesContainingStopWords\" ] || (echo -e \"ERROR: The following lines contain stop words:\\n${linesContainingStopWords}\" && exit 1)"
    - echo "----- No stop words found -----"

The output is not exactly beautiful:

$ range="origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..${CI_COMMIT_SHORT_SHA}"
$ echo "Inspecting ${range}"
Inspecting origin/master..11a9b64a
$ git fetch --depth=${GIT_DEPTH} origin ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
From https://192.168.178.164/dev/ioxp
 * branch                master     -> FETCH_HEAD
$ messageWithoutTags=$(git rev-list -E --invert-grep --grep '^((Merge branch .+)|(Merge remote-tracking branch .+)|(Accumulated commit of .+)|(Revert .?)|(\[([A-z0-9])+\].{5,}))' "${range}")
$ [ -z "$messageWithoutTags" ] || (echo -e "ERROR: The following commit messages don't follow the [tag] pattern:\n$(echo "${messageWithoutTags}" | xargs -n1 git log --format=%s -n 1)" && exit 1)
$ echo "----- Commit messages are okay -----"
----- Commit messages are okay -----
$ stopWords="NO COMMIT\|NO MERGE\|NOCOMMIT\|NOMERGE"
$ linesContainingStopWords=$( (git diff -p -M ${range} -- . ':!.gitlab-ci.yml' | ./showlinenum.awk show_path=1 | grep -E '^.+[0-9]+:\+' | grep "${stopWords}" ) || echo "")
$ [ -z "$linesContainingStopWords" ] || (echo -e "ERROR: The following lines contain stop words:\n${linesContainingStopWords}" && exit 1)
$ echo "----- No stop words found -----"
----- No stop words found -----
Edited by Philipp Hasper