Skip to content
Snippets Groups Projects
Commit 87c384c5 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[bin][runcommand] make it possible to suppress traceback

The commands (e.g. pipeline queries via API) may contain sensible
information that we don't want to display e.g. in the output of jobs
from the GitLab CI
parent 35e1f629
No related branches found
No related tags found
1 merge request!2644Feature/continuous master pipeline status
...@@ -5,23 +5,27 @@ import subprocess ...@@ -5,23 +5,27 @@ import subprocess
# execute a command and retrieve the output # execute a command and retrieve the output
def runCommand(command): def runCommand(command, suppressTraceBack=False, errorMessage=''):
try: try:
return subprocess.run(command, return subprocess.run(command,
shell=True, check=True, shell=True, check=True,
text=True, capture_output=True).stdout text=True, capture_output=True).stdout
except Exception: except Exception:
print() if suppressTraceBack:
print("An error occurred during subprocess run:") sys.excepthook(Exception, Exception(errorMessage), None)
print("-- command: {}".format(command)) elif not errorMessage:
print("-- folder: {}".format(os.getcwd())) print("An error occurred during subprocess run:")
print("-- error: {}".format(sys.exc_info()[1])) print("-- command: {}".format(command))
if "git " in command: print("-- folder: {}".format(os.getcwd()))
print() print("-- error: {}".format(sys.exc_info()[1]))
print("It seems that a git command failed. Please check:\n" if "git " in command:
" -- is the module registered as git repository?\n" print()
" -- is upstream defined for the branch?\n") print("It seems that a git command failed. Please check:\n"
raise " -- is the module registered as git repository?\n"
" -- is upstream defined for the branch?\n")
raise
else:
raise Exception(errorMessage)
# decorator to call function from within the given path # decorator to call function from within the given path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment