diff --git a/src/pipeline.sh b/src/pipeline.sh index f62d65e..005964f 100755 --- a/src/pipeline.sh +++ b/src/pipeline.sh @@ -130,7 +130,39 @@ main() ( usage fail "Missing positionnal argument PIPELINE." fi + + # Check pipeline validity. pipeline="$1" + case "${pipeline}" in + newcommit) + if [ -z "${repo_name}" ]; then + usage + fail "missing option -n|--name for pipeline '${pipeline}'." + fi + if [ -z "${repo_hash}" ]; then + usage + fail "missing option -h|--hash for pipeline '${pipeline}'." + fi + ;; + newtag) + if [ -z "${repo_name}" ]; then + usage + fail "Missing option -n|--name for pipeline '${pipeline}'." + fi + if [ -z "${repo_hash}" ]; then + usage + fail "Missing option -H|--hash for pipeline '${pipeline}'." + fi + if [ -z "${repo_tag}" ]; then + usage + fail "Missing option -T|--tag for pipeline '${pipeline}'." + fi + ;; + *) + usage + fail "Unexpected value for PIPELINE: '${pipeline}'." + ;; + esac # Load config file. if [ ! -r "${config_file}" ]; then @@ -189,17 +221,9 @@ main() ( rd_pipeline_sock_dir="${pipeline_sock_dir}/${pipeline}-${tsp}-${random}" rd_pipeline_sock="${rd_pipeline_sock_dir}/pipeline.sock" - # Check pipeline with options. + # Build runner request. case "${pipeline}" in newcommit) - if [ -z "${repo_name}" ]; then - usage - fail "Missing option -n|--name for pipeline '${pipeline}'." - fi - if [ -z "${repo_hash}" ]; then - usage - fail "Missing option -H|--hash for pipeline '${pipeline}'." - fi runner_request="$(jq --null-input --compact-output \ --arg s "${rd_pipeline_sock}" \ --arg n "${repo_name}" \ @@ -207,18 +231,6 @@ main() ( '{"response_sock":$s,"repo_name":$n,"repo_hash":$h}')" ;; newtag) - if [ -z "${repo_name}" ]; then - usage - fail "Missing option -n|--name for pipeline '${pipeline}'." - fi - if [ -z "${repo_hash}" ]; then - usage - fail "Missing option -H|--hash for pipeline '${pipeline}'." - fi - if [ -z "${repo_tag}" ]; then - usage - fail "Missing option -T|--tag for pipeline '${pipeline}'." - fi runner_request="$(jq --null-input --compact-output \ --arg s "${rd_pipeline_sock}" \ --arg n "${repo_name}" \