我正在开展项目,我有两个Git Repos:
Repo1 - DevRepo,Rep02- TestRepo
我的情景是: 无论何时在Repo1上发生提交或PR:
步骤1:应立即触发Repo2
步骤2:Step1成功后,应触发Repo1。
基本上Repo1只有在Repo2运行并且成功时才会构建。
有人可以帮助我如何设置它,非常感谢:
答案 0 :(得分:1)
答案:我有这个工作:
` 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
答案 1 :(得分:1)
我现在为此目的建立了CI服务。它住在这里:https://github.com/cesium-ml/dependent_build_server
以上代码基本上执行以下操作:
注意:您必须验证来自GitHub和Travis-CI的有效负载。这对于GitHub来说是微不足道的,但对于使用正确密钥签名的Travis-CI来说稍微困难一些。
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)
特拉维斯-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