Use current revision in a build
It is often useful to use the current version control revision number in your build. For example, you might want to use the svn version number in the name of your binary for tracing purposes. Cruise makes much of this information available to your build scripts as environment variables.
Example usages
One material
For this example, we are going to assume we are using a single Subversion repository for our source control system and we have a job set up to call the ant target "dist".
- Add the following target to your ant build.xml
build.xml
<project name="test-build">
<property environment="env" />
<target name="dist">
<echo message="Building pipeline ${env.CRUISE_PIPELINE_NAME}"
file="deploy-${env.CRUISE_REVISION}.txt" />
</target>
</project>
deploy-123.txt Building pipeline my-app
Multiple materials
For this example we are going to assume we are using a Subversion repository containing the code and a Mercurial repository containing configuration scripts.
- Ensure the pipeline materials look like this
<pipeline name="multiple-materials">
<materials>
<svn url="..." dest="code" />
<hg url="..." dest="configuration/latest" />
</materials>
...
</pipeline>
build.xml
<project name="my-app">
<property environment="env" />
<target name="dist">
<echo message="Building pipeline ${env.CRUISE_PIPELINE_NAME}"
file="deploy-${env.CRUISE_REVISION_CODE}.txt" />
<echo message="Configuration version: ${env.CRUISE_REVISION_CONFIGURATION_LATEST}"
file="deploy-${env.CRUISE_REVISION_CODE}.txt"
append="true" />
</target>
</project>
deploy-123.txt Building pipeline my-app Configuration version: 59cab75ccf231b9e338c96cff0f4adad5cb7d335
All Cruise environment variables
| Environment Variable | Description | Example contents |
|---|---|---|
| CRUISE_SERVER_URL | Base URL for the Cruise server (including the context root) |
https://127.0.0.1:8154/cruise |
| CRUISE_PIPELINE_NAME | Name of the current pipeline being run |
cruise |
| CRUISE_PIPELINE_LABEL | Label for the current pipeline. By default, this is set to the pipeline count (this can be set to a custom pipeline label) |
1.1.2345 |
| CRUISE_STAGE_NAME | Name of the current stage being run |
dev |
| CRUISE_STAGE_COUNTER | How many times the current stage has been run |
1 |
| CRUISE_JOB_NAME | Name of the current job being run |
linux-firefox |
| CRUISE_DEPENDENCY_LABEL_ ${pipeline name}_${stage name} | The label of the upstream pipeline (when using dependant pipelines) |
1.0.3456 |
| CRUISE_REVISION | The current source control revision being run (when using only one material |
123 |
| CRUISE_REVISION_ ${material dest} | If you are using more than one material in your pipeline the revision for each material is available. The environment variable is names with the material's "dest" directory. Non alphanumeric characters are replaced with underscores("_"). |
456 |