edebill
edebill

Reputation: 7715

Triggering builds of dependent projects in Travis CI

We have our single page javascript app in one repository and our backend server in another. Is there any way for a passing build on the backend server to trigger a build of the single page app?

We don't want to combine them into a single repository, but we do want to make sure that changes to one don't break the other.

Upvotes: 16

Views: 3260

Answers (2)

boly38
boly38

Reputation: 1955

It's possible yes and it's also possible to wait related build result.

I discover trigger-travis.sh from the previous answer but before that I was implementing my own solution (for full working source code: cf. pending pull request PR196 and live result)

References

Based on travis API v3 documentation:

You will need a travis token, and setup this token as secreet environment variable on travis portal.

Following this doc, I were able to trigger a build, and wait for him.

1) make .travis_hook_qa.sh

(extract) - to trigger a new build :

REQUEST_RESULT=$(curl -s -X POST \
   -H "Content-Type: application/json" \
   -H "Accept: application/json" \
   -H "Travis-API-Version: 3" \
   -H "Authorization: token ${QA_TOKEN}" \
   -d "$body" \
   https://api.travis-ci.org/repo/${QA_SLUG}/requests)

(it's trigger-travis.sh equivalent) You could make some customization on the build definition (with $body)

2) make .travis_wait_build.sh

(extract) - to wait a just created build, get build info :

    BUILD_INFO=$(curl -s -X GET \
       -H "Content-Type: application/json" \
       -H "Accept: application/json" \
       -H "Travis-API-Version: 3" \
       -H "Authorization: token ${QA_TOKEN}" \
       https://api.travis-ci.org/repo/${QA_SLUG}/builds?include=build.state\&include=build.id\&include=build.started_at\&branch.name=master\&sort_by=started_atdesc\&limit=1 )
    BUILD_STATE=$(echo "${BUILD_INFO}" | grep -Po '"state":.*?[^\\]",'|head -n1| awk -F "\"" '{print $4}')
    BUILD_ID=$(echo "${BUILD_INFO}" | grep '"id": '|head -n1| awk -F'[ ,]' '{print $8}')

You will have to wait until your timeout or expected final state..

Reminder: possible travis build states are created|started (and then) passed|failed

Upvotes: 1

mernst
mernst

Reputation: 8157

Yes, it is possible to trigger another Travis job after a first one succeeds. You can use the trigger-travis.sh script.

The script's documentation tells how to use it -- set an environment variable and add a few lines to your .travis.yml file.

Upvotes: 10

Related Questions