User Tools

Site Tools


gitlab_satis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gitlab_satis [2018/11/14 15:12]
admin [Configuration]
gitlab_satis [2018/11/14 16:54] (current)
admin [Optional]
Line 113: Line 113:
 <code ruby gitlab_pages_satis.rb> <code ruby gitlab_pages_satis.rb>
 #!/usr/bin/env ruby #!/usr/bin/env ruby
 +
 +#### Config begin
 +
 +# Trigger Token, see Project -> Settings -> CI/CD -> Pipeline triggers
 +trigger_token="XXXXXXXX"
 +
 +# Private Token, see User -> Access Tokens -> Personal Access Tokens
 +auth_token="XXXXXXXX"
 +
 +# GitLab install
 +gitlab_url="https://gitlab.example.org/"
 +
 +# Satis Project id (integer, not the project name)
 +satis_project_id="XX"
 +
 +#### Config end
  
 require 'json' require 'json'
Line 118: Line 134:
  
 payload = JSON.parse(STDIN.read) payload = JSON.parse(STDIN.read)
- 
  
 # Only run this code in case we are dealing with tag_push event # Only run this code in case we are dealing with tag_push event
Line 133: Line 148:
  File.delete(shaFile) if File.exist?(shaFile)  File.delete(shaFile) if File.exist?(shaFile)
  File.write(shaFile, "#{payload['ref']}")  File.write(shaFile, "#{payload['ref']}")
 +
 + # Check if composer files exists in project
 + project_id="#{payload['project_id']}"
 + composerExists = `curl -o /dev/null -s -w \"%{http_code}\" --request GET --header 'PRIVATE-TOKEN: #{auth_token}' '#{gitlab_url}/api/v4/projects/#{project_id}/repository/files/composer%2Ejson/raw?ref=master'`
  
  # Trigger Pipeline  # Trigger Pipeline
-  if payloadBefore != payloadCurrent¬†+  if payloadBefore != payloadCurrent && composerExists == '200'¬†
-  exec('curl --request POST --form "token=XXXXXXXXX" --form ref=master https://gitlab.domain.com/api/v4/projects/{YOUR_SATIS_PROJECT_ID}/trigger/pipeline')+  exec("curl --request POST --form \"token=#{trigger_token}\" --form ref=master #{gitlab_url}/api/v4/projects/#{satis_project_id}/trigger/pipeline")
  end  end
   
 end end
 </code> </code>
gitlab_satis.1542204745.txt.gz · Last modified: 2018/11/14 15:12 by admin