From 8ebfd5c45cd25e5bce147467c5946eb76ee1d154 Mon Sep 17 00:00:00 2001 From: Bjørn Forsman Date: Wed, 28 Nov 2018 07:03:19 +0100 Subject: nixos/jenkins-job-builder: stop reloadScript on error Currently there are two calls to curl in the reloadScript, neither which check for errors. If something is misconfigured (like wrong authToken), the only trace that something wrong happened is this log message: Asking Jenkins to reload config

Bad Message 400

reason: Illegal character VCHAR='<'
The service isn't marked as failed, so it's easy to miss. Fix it by passing --fail to curl. While at it: * Add $curl_opts and $jenkins_url variables to keep the curl command lines DRY. * Add --show-error to curl to show short error message explanation when things go wrong (like HTTP 401 error). * Lower-case the $CRUMB variable as upper case is for exported environment variables. The new behaviour, when having wrong accessToken: Asking Jenkins to reload config curl: (22) The requested URL returned error: 401 And the service is clearly marked as failed in `systemctl --failed`. --- .../modules/services/continuous-integration/jenkins/job-builder.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/continuous-integration/jenkins/job-builder.nix b/nixos/modules/services/continuous-integration/jenkins/job-builder.nix index 861b46a2d64..682586b83e3 100644 --- a/nixos/modules/services/continuous-integration/jenkins/job-builder.nix +++ b/nixos/modules/services/continuous-integration/jenkins/job-builder.nix @@ -128,8 +128,10 @@ in { ownerStamp = ".config-xml-managed-by-nixos-jenkins-job-builder"; reloadScript = '' echo "Asking Jenkins to reload config" - CRUMB=$(curl -s 'http://${cfg.accessUser}:${cfg.accessToken}@${jenkinsCfg.listenAddress}:${toString jenkinsCfg.port}${jenkinsCfg.prefix}/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') - curl --silent -X POST -H "$CRUMB" http://${cfg.accessUser}:${cfg.accessToken}@${jenkinsCfg.listenAddress}:${toString jenkinsCfg.port}${jenkinsCfg.prefix}/reload + curl_opts="--silent --fail --show-error" + jenkins_url="http://${cfg.accessUser}:${accessToken}@${jenkinsCfg.listenAddress}:${toString jenkinsCfg.port}${jenkinsCfg.prefix}" + crumb=$(curl $curl_opts "$jenkins_url"'/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') + curl $curl_opts -X POST -H "$crumb" "$jenkins_url"/reload ''; in '' -- cgit 1.4.1