Using Travis CI with a Software Delivery Machine
While Atomist is perfectly capable of handling CI tasks, there are other tools out there that can handle this task as well. Travis, for example, is a very compelling choice for CI when you're on GitHub.com.
Atomist works perfectly with Travis and it doesn't take a lot of work in order to get the two tools working alongside each other. First of all, you need to have your GitHub organization linked to Travis, so that Travis can actually see commits coming from your repositories and kick off builds.
First we'll build an SDM that is capable of interacting with Travis builds.
const sdm: SoftwareDeliveryMachine = createSoftwareDeliveryMachine(
{
name: "Spring Software Delivery Machine",
configuration,
});
const build = new Build().with({
externalTool: "travis",
});
const BuildGoals = goals("build")
.plan(build);
sdm.addGoalContributions(goalContributors(
whenPushSatisfies(HasTravisFile).setGoals(BuildGoals),
));
sdm.addGeneratorCommand<SpringProjectCreationParameters>({
name: "create-spring",
intent: "create spring",
description: "Create a new Java Spring Boot REST service",
parameters: SpringProjectCreationParameterDefinitions,
startingPoint: GitHubRepoRef.from({ owner: "atomist-seeds", repo: "spring-rest-seed", branch: "master" }),
transform: [
ReplaceReadmeTitle,
SetAtomistTeamInApplicationYml,
TransformSeedToCustomProject,
],
});
What is special here is the definition of the Build
goal:
const build = new Build().with({
externalTool: "travis",
});
This tells Atomist not to perform a build, but rely on an external build tool to handle the build, in this case Travis CI.
If we start up this SDM, we can create a new Spring project in the Slack workspace that is linked to Atomist.
@atomist create spring
After creation, you'll notice that there aren't any goals that are being planned or executed. That's because we configured Atomist only to schedule the build goal if there is a Travis file present
whenPushSatisfies(HasTravisFile).setGoals(BuildGoals)
Additionally, you need to tell Travis to observe your project for changes. That last task is something that you need to do in your Travis configuration.
Creating a Travis file, however, is something that Atomist can help you with by providing a code transform.
function AddTravisFile(workspaceIds: string[]): CodeTransform {
const TravisYAML = `language: java
notifications:
webhooks:
urls:
${_.join(workspaceIds.map(id => " - https://webhook.atomist.com/atomist/travis/teams/" + id), "\n")}
on_success: always
on_failure: always
on_start: always
on_cancel: always
on_error: always
`;
return p => {
return p.addFile(".travis.yml", TravisYAML);
};
}
This code transform will add a .travis.yml
file to your project which has been configured to build Java projects and communicate back to Atomist when a build has succeeded (or failed).
Applying this code transform is done by creating a command that allows you to issue the add travis yml
command to Atomist.
sdm.addCodeTransformCommand({
name: "Add Travis YML",
intent: "add travis yml",
transform: AddTravisFile(sdm.configuration.workspaceIds),
transformPresentation: () => {
const pr: BranchCommit = {
message: "Add .travis.yml file",
branch: "travis-yml",
autoMerge: {
mode: AutoMergeMode.SuccessfulCheck,
method: AutoMergeMethod.Squash,
},
};
return pr;
},
});
So if you enabled your project in Travis you can now issue the following command in your project's Slack channel:
@atomist add travis yml
Atomist will add a Travis YML file and trigger a build goal. However, this goal will not do the build, but will wait until Travis signals Atomist that the build has succeeded.
So while Atomist is capable of handling your builds, you can offload that work to external systems just as easily.