Continuous Integration - tooltwist/documentation GitHub Wiki
We recently switched to using CircleCI for doing Continuous Integration. We may change over to Shippable but haven't yet evaluated this service.
CircleCI is a cloud-based service that integrates closely with Github (and BitBucket?) and takes only a couple of minutes to set up. When you sign up you use your Github account, and this allows CircleCI to access your Github repositories.
Once you add a repository to CircleCI, every time the repository is updated (via a Git push) the code will get pulled out into CircleCI, which will build it, run tests, and email developers of any problems.
Projects/Repositories can be added to CircleCI by selecting the Add Project menu option on the left.
Deploying extension projects
ToolTwist v8.3+ extension projects can be quickly added to CircleCI:
Preparing the project
-
The project must first be building with Gradle and set up for publishing to Artifactory.
-
Check the project has gradlew files. If it does not, run
gradle wrapper
and the files will be created for you. -
Some examples for build.gradle in this wiki might need to be corrected. Check you have the following definitions:
buildscript { repositories { maven { url 'http://jcenter.bintray.com' } } dependencies { classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9') } }
And also:
// Note that tests only get run when the code changes
test {
testLogging {
// Show that tests are run in the command-line output
events "passed", "skipped", "failed"
}
}
Credentials
All credentials for accessing Artifactory, except for username and password, should be defined in a gradle.properties
file in the project directory. These other variables should be defined in ~/.gradle/gradle.properties
. This separation prevents the credentials from becoming visible in the public Github repository.
circleci.yml
This configuration tells circleCI how to build the project.
$ cat circle.yml
test:
override:
- ./gradlew test artifactoryPublish
general:
artifacts:
- "build/reports/tests" # relative to the build directory
The second part instructs CircleCI to make JUnit test reports viewable over the web interface.
Environment variables
The username and password properties defined as Gradle properties will not be store in Github, so need top be provided by CircleCI. Gradle has the ability to use environment variables to define properties, simply by putting a ORG_GRADLE_PROJECT_
prefix on the name of the property. For example, a property named ARTIFACTORY_USER
can be provided by an environment variable named ORG_GRADLE_PROJECT_ARTIFACTORY_USER
, similarly for `ORG_GRADLE_PROJECT_ARTIFACTORY_PASSWORD.
It's unwieldy, but it works. To set properties, select a project then click on the gear icon on the top right, then select the Environment Variable menu option.
When Gradle runs, it rewrites a progress message after each line of output. This allow the output to scroll, with the line under the cursor always showing the current task being run. This works fine on an interactive terminal, but when the output is redirected to file it becomes unreadable because the build output becomes hidden within the progress messages repeated a hundred times.
0/1 projects > root project > 4 KB/167 KB downloaded7 KB/167 KB downloaded11 KB/167 KB downloaded5 KB/167 KB downloaded6 KB/167 KB downloaded20 KB/167 KB downloaded4 KB/167 KB downloaded8 KB/167 KB downloaded32 KB/167 KB downloaded3 KB/167 KB downloaded7 KB/167 KB downloaded41 KB/167 KB downloaded5 KB/167 KB downloaded7 KB/167 KB...
To prevent this, set the following environment variable:
TERM=dumb
Status Badges
Beneath the Environment Variables menu option is a Status Badges option. On this page is a snippet of code that can be pasted into the README.md
file for the project on Github. This will display a colorful icon on the project home page in Guthub, showing the current build status of the project.
Building
Any time anyone pushes changes to Github, the project will build.
Emails will be sent to users when the build fails, and the results of JUnit tests can be viewed under the Build Artifacts section of the build report.
If the build succeeds, the extension project will be published as a snapshot to Artifactory, where it can be included in all developer's projects.
Debugging Builds
If the build does not work correctly, it can be debugged by pressing & enable SSH
at the top right. This will start the build and pause before shutting down the session. It will display a command that can be used to SSH into the server and run the build manually.
Building Webdesign Projects
This is still work in progress:
- user pushes to github
- CircleCI runs ToolTwist CLI to build the application into a Docker container.
- Protractor/Selenium is used to test the application.
- If tests pass the Docker container is pushed to Dockerhub.
Links
Maybe not relevant...
http://eugenedvorkin.com/continuous-delivery-pipeline-with-jenkins-gradle-and-artifactory-part-1-commit-stage/