diff --git a/src/pipeline.sh b/src/pipeline.sh index 425143e..52a1c97 100755 --- a/src/pipeline.sh +++ b/src/pipeline.sh @@ -132,6 +132,45 @@ main() ( fi pipeline="$1" + # Load config file. + if [ ! -r "${config_file}" ]; then + fail "Config file '${config_file}' is not readable." + fi + # shellcheck source=./conf/netoik-cicd.conf.sample + source "${config_file}" + + # Load errors file. + if [ ! -r "${errors_file}" ]; then + fail "Errors file '${errors_file}' is not reachable." + fi + # shellcheck source=./conf/errors.conf.sample + source "${errors_file}" + + # Check variables in config file. + if [ -z "${runner_sock}" ]; then + fail "Variable runner_sock is empty." "${err_runner_sock_empty}" + fi + if [ ! -S "${runner_sock}" ]; then + fail "Sock runner_sock='${runner_sock}' does not exist." \ + "${err_runner_sock_not_exist}" + fi + + if [ -z "${runner_timeout}" ]; then + fail "Variable runner_timeout is empty." "${err_runner_timeout_empty}" + fi + if [ "${runner_timeout}" -lt 0 ]; then + fail "Runner timeout is not valid: ${runner_timeout}." \ + "${err_runner_timeout_not_valid}" + fi + + if [ -z "${git_runner_groupname}" ]; then + fail "Variable git_runner_groupname is empty." "${err_git_runner_groupname_empty}" + fi + if ! getent group "${git_runner_groupname}"; then + fail "Git-runner group '${git_runner_groupname}' does not exist." \ + "${err_git_runner_group_not_exist}" + fi + # Generate pipeline tmp sock. tsp="$(date +%s)" random="$(echo "${RANDOM}" | md5sum | head --bytes 32)" @@ -181,45 +220,6 @@ main() ( ;; esac - # Load config file. - if [ ! -r "${config_file}" ]; then - fail "Config file '${config_file}' is not readable." - fi - # shellcheck source=./conf/netoik-cicd.conf.sample - source "${config_file}" - - # Load errors file. - if [ ! -r "${errors_file}" ]; then - fail "Errors file '${errors_file}' is not reachable." - fi - # shellcheck source=./conf/errors.conf.sample - source "${errors_file}" - - # Check variables in config file. - if [ -z "${runner_sock}" ]; then - fail "Variable runner_sock is empty." "${err_runner_sock_empty}" - fi - if [ ! -S "${runner_sock}" ]; then - fail "Sock runner_sock='${runner_sock}' does not exist." \ - "${err_runner_sock_not_exist}" - fi - - if [ -z "${runner_timeout}" ]; then - fail "Variable runner_timeout is empty." "${err_runner_timeout_empty}" - fi - if [ "${runner_timeout}" -lt 0 ]; then - fail "Runner timeout is not valid: ${runner_timeout}." \ - "${err_runner_timeout_not_valid}" - fi - - if [ -z "${git_runner_groupname}" ]; then - fail "Variable git_runner_groupname is empty." "${err_git_runner_groupname_empty}" - fi - if ! getent group "${git_runner_groupname}"; then - fail "Git-runner group '${git_runner_groupname}' does not exist." \ - "${err_git_runner_group_not_exist}" - fi - # Stop now if testing. if "${testing}"; then exit 0