Reputation: 479
I'm working on project, where I have two Git Repos:
Repo1 - DevRepo, Rep02- TestRepo
My Scenario is: Whenever a commit or a PR happens on the Repo1:
Step1: Immediately Repo2 should be triggered
Step2: Once Step1 is success, Repo1 should be triggered.
Basically Repo1 should build only if Repo2 is run and it turns success.
Could someone please help me how I can set this up, much appreciated:
Upvotes: 4
Views: 512
Reputation: 7253
I've now built a CI service for this purpose. It lives here: https://github.com/cesium-ml/dependent_build_server
The above code basically does the following:
Note: You have to verify the payloads that come from GitHub and Travis-CI. This is trivial for GitHub, but slightly harder for Travis-CI which uses proper key signing.
GitHub:
import hmac
def verify_signature(payload, signature, secret):
expected = 'sha1=' + hmac.new(secret.encode('ascii'),
payload, 'sha1').hexdigest()
return hmac.compare_digest(signature, expected)
Travis-CI:
from OpenSSL import crypto
def verify_signature(payload, signature):
# Get this by querying the Travis-CI config API
public_key = crypto.load_publickey(crypto.FILETYPE_PEM, pubkey)
certificate = crypto.X509()
certificate.set_pubkey(public_key)
try:
crypto.verify(certificate, signature, payload, 'sha1')
return True
except crypto.Error:
return False
Upvotes: 1
Reputation: 479
Answer: I got this working:
` body='{ "request": { "branch":"master" }}' curl -s -X POST \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -H "Travis-API-Version: 3" \ -H "Authorization: token ..git_hub_login_token.." \ -d "$body" \ https://api.travis-ci.org/repo/xxxx%2Fyyyy/requests #The 15s sleep is to allow Travis to trigger the dependent build: sleep 15`
# Polling for the Repo2 build status # Setting a maximum time for the Repo2 build to run, however once we get the status to passed/failed, we will return to the Repo1 build run `i=1 max=300 while [ $i -lt $max ] do echo "--------------------------------------------" echo "Polling for the tests run build status..."` curl -i -H "Accept: application/vnd.travis-ci.2+json" "https://api.travis-ci.org/repos/xxxx/yyyy/builds" > test.json LATEST_STATE=$(grep -o '"state":.[a-z\"]*' test.json | head -1) #LATEST_ID=$(grep -o '"id":.[0-9]*' test.json | head -1 | grep ':.[0-9]*') get_state_value=${LATEST_STATE#*:} STATE="${get_state_value//\"}" if [ $STATE == "passed" ] then echo "TESTS RUN... $STATE :-) " break #As soon as the Repo2 run pass, we break and return back to the Repo1 build run elif [ $STATE == "failed" ] then echo "TESTS RUN... $STATE :-(" echo "Stop building elements" exit 1 #As soon as the Repo2 run fail, we stop building Repo1 fi true $(( i++ )) sleep 1 #This 1s is required to poll the build status for every second done
script: - chmod 777 ./trigger_build.sh - chmod 777 ./get_build_status.sh - ./trigger_build.sh - ./get_build_status.sh
Upvotes: 1