jenkins and bash

95 праглядаў
Перайсці да першага непрачытанага паведамлення

Gil Jensen

не прачытана,
5 сак 2021 г., 12:12:035.03.21
да Jenkins Users
I have set up several jenkins jobs that do nothing more than execute bas scripts, howevwe The bash scripts run fine and complete with no errors in the but jenkins runs and gets errors is there a right way to debug this?

Amedee Van Gasse

не прачытана,
6 сак 2021 г., 14:30:106.03.21
да Jenkins Users
Put this as the first line in your shell scripts:

#!/bin/bash -ex

-e exits the script immediately if a command exits with a non-zero status.
-x echos the current line in the script when it's executed.

My best guess is that an error occurs in your script, which is silently ignored by Bash, but at the end of the script you still have a non-zero status.
Jenkins checks for that non-zero status and fails.


Secondly, verify your scripts with https://www.shellcheck.net/
You can use ShellCheck online, install it on your local machine, and even integrate it with most major editors.
Make sure that ShellCheck says "No issues detected!"


Without actually seeing the code of your shell scripts, it's at this point not possible to give you any further debugging tips.

Hope this helps!

-- 
Amedee

Ivan Fernandez Calvo

не прачытана,
7 сак 2021 г., 08:32:117.03.21
да Jenkins Users
A common issue is that you are not using the same shell, for example on Ubuntu by default is common to have installed dash as the default shell, this causes troubles when you use bash only features. A good practice is to set the first line to "#!/bin/bash" or "#!/usr/bin/env bash" and set -exuo pipefail (see https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/) as Amedee said. I am a fan of use pre-commit (https://pre-commit.com/index.html) to validate everything before committing to the repo; pre-commit has a hook to check scripts with shellcheck it is really helpful to avoid stupid mistakes and normalize the way all scripts are made.
Адказаць усім
Адказаць аўтару
Наперад
0 новых паведамленняў