我正在做项目,我有两个
Git Repos:
Repo1 – DevRepo,Rep02- TestRepo
我的情景是:
每当在Repo1上发生提交或PR时:
步骤1:应立即触发Repo2
步骤2:Step1成功后,应触发Repo1.
基本上Repo1只有在Repo2运行并且成功时才会构建.
有人可以帮助我如何设置它,非常感谢:
>我应该配置哪个.travis.yml文件来满足我的场景.
>我可以在.travis.yml文件中编写的确切配置步骤
最佳答案 答:我得到了这个工作:
>使用travis api触发您的依赖构建:Repo2:
创建一个trigger_build.sh文件并添加以下代码:
` 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`
>创建一个新的或单独的get_build_status.sh文件.轮询依赖构建的状态.根据Repo2构建的状态,我们将继续构建Repo1或停止构建Repo1:
# 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
>您的.travis.yml配置:
script: - chmod 777 ./trigger_build.sh - chmod 777 ./get_build_status.sh - ./trigger_build.sh - ./get_build_status.sh