From c44680d1b8e0d14ab46f5785c508b286ee9271b8 Mon Sep 17 00:00:00 2001 From: Balasankar C Date: Tue, 9 May 2017 01:59:27 +0530 Subject: Print triggered pipeline id in a better format --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 588f255eff8..39546e888d2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -141,6 +141,7 @@ stages: # Trigger a package build on omnibus-gitlab repository build-package: + before_script: [] services: [] variables: SETUP_DB: "false" @@ -157,7 +158,8 @@ build-package: # Collect version details of all components - for f in *_VERSION; do echo "variables[$f]=$(cat $f)" >> version_details; done # Trigger the API and pass values collected above as parameters to it - - cat version_details | tr '\n' '&' | curl -X POST https://gitlab.com/api/v4/projects/20699/trigger/pipeline --data-binary @- + - pipeline_id=$(cat version_details | tr '\n' '&' | curl -s -X POST https://gitlab.com/api/v4/projects/20699/trigger/pipeline --data-binary @- | ruby -e "require 'json'; puts JSON.parse(STDIN.read)['id']") > /dev/null + - echo "Triggered pipeline can be found at https://gitlab.com/gitlab-org/omnibus-gitlab/pipelines/${pipeline_id}" - rm version_details # Prepare and merge knapsack tests -- cgit v1.2.1 From e85aa42428e2ab77ed74317b481351197e34e1e3 Mon Sep 17 00:00:00 2001 From: Balasankar C Date: Tue, 9 May 2017 15:19:48 +0530 Subject: Move triggering build logic to separate script --- .gitlab-ci.yml | 13 +------------ scripts/trigger-build | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100755 scripts/trigger-build diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 39546e888d2..88d536fa9b3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -149,18 +149,7 @@ build-package: stage: build when: manual script: - # If no branch in omnibus is specified, trigger pipeline against master - - if [ -z "$OMNIBUS_BRANCH" ] ; then export OMNIBUS_BRANCH=master ;fi - - echo "token=${BUILD_TRIGGER_TOKEN}" > version_details - - echo "ref=${OMNIBUS_BRANCH}" >> version_details - - echo "variables[ALTERNATIVE_SOURCES]=true" >> version_details - - echo "variables[GITLAB_VERSION]=${CI_COMMIT_SHA}" >> version_details - # Collect version details of all components - - for f in *_VERSION; do echo "variables[$f]=$(cat $f)" >> version_details; done - # Trigger the API and pass values collected above as parameters to it - - pipeline_id=$(cat version_details | tr '\n' '&' | curl -s -X POST https://gitlab.com/api/v4/projects/20699/trigger/pipeline --data-binary @- | ruby -e "require 'json'; puts JSON.parse(STDIN.read)['id']") > /dev/null - - echo "Triggered pipeline can be found at https://gitlab.com/gitlab-org/omnibus-gitlab/pipelines/${pipeline_id}" - - rm version_details + - scripts/trigger-build # Prepare and merge knapsack tests knapsack: diff --git a/scripts/trigger-build b/scripts/trigger-build new file mode 100755 index 00000000000..ccdb01c96ca --- /dev/null +++ b/scripts/trigger-build @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +require 'net/http' +require 'json' + +uri = URI('https://gitlab.com/api/v4/projects/20699/trigger/pipeline') +params = { + "token" => ENV['BUILD_TRIGGER_TOKEN'], + "variables[GITLAB_VERSION]" => ENV['CI_COMMIT_SHA'], + "variables[ALTERNATIVE_SOURCES]" => true, +} +params['ref'] = ENV['OMNIBUS_BRANCH'] || "master" +Dir.glob("*_VERSION").each do |version_file| + params["variables[#{version_file}]"] = File.read(version_file).strip +end +res = Net::HTTP.post_form(uri, params) +pipeline_id = JSON.parse(res.body)['id'] +puts "Triggered pipeline can be found at https://gitlab.com/gitlab-org/omnibus-gitlab/pipelines/#{pipeline_id}" -- cgit v1.2.1 From 784941eee6fb3ce8b2cdccf2eb75e908a9b15d7a Mon Sep 17 00:00:00 2001 From: Balasankar C Date: Tue, 9 May 2017 18:51:32 +0530 Subject: Improve readability of code --- scripts/trigger-build | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/trigger-build b/scripts/trigger-build index ccdb01c96ca..741e6361f01 100755 --- a/scripts/trigger-build +++ b/scripts/trigger-build @@ -5,14 +5,17 @@ require 'json' uri = URI('https://gitlab.com/api/v4/projects/20699/trigger/pipeline') params = { - "token" => ENV['BUILD_TRIGGER_TOKEN'], - "variables[GITLAB_VERSION]" => ENV['CI_COMMIT_SHA'], + "ref" => ENV["OMNIBUS_BRANCH"] || "master", + "token" => ENV["BUILD_TRIGGER_TOKEN"], + "variables[GITLAB_VERSION]" => ENV["CI_COMMIT_SHA"], "variables[ALTERNATIVE_SOURCES]" => true, } -params['ref'] = ENV['OMNIBUS_BRANCH'] || "master" + Dir.glob("*_VERSION").each do |version_file| params["variables[#{version_file}]"] = File.read(version_file).strip end + res = Net::HTTP.post_form(uri, params) pipeline_id = JSON.parse(res.body)['id'] + puts "Triggered pipeline can be found at https://gitlab.com/gitlab-org/omnibus-gitlab/pipelines/#{pipeline_id}" -- cgit v1.2.1