In our hudson setup we have several jobs per project. For example we’ll have:
- build – compiles and runs tests.
- integration – runs integration tests. triggered by build’s success
- devstage – ftp’s our project to the development test environment. triggered by the build’s success.
- release to live boxes. This is a manual trigger.
Each of these jobs has a hudson build number, however only the “build” job’s build matters, because that references the code built, and includes the source control changeset details, including the commit messages. We also use it to generate part of the version number of our product. When we release to the dev environment and the live environment, we use the build number as the version number. When there’s 7 different build numbers, and if you decide to change the name of one of your jobs, this can become very confusing, very quickly.
So we decided we’d like all the child jobs (or downstream) which clone the build workspace, should also have the build’s number. Having a look around for hudson plugins, couldn’t find much to help. There’s the Parameterized Trigger Plugin which works brilliantly, aside from the release jobs which are manually triggered. Then we found the Envfile Plugin. This has absolutely no documentation, so I thought I’d share what we did:
- install the Envfile Plugin into Hudson
- create a powershell script in your project to create a file setting the required environment variable when the build job is running. Format of the environment variable is VARIABLE_NAME=VALUE. Note the usual SET VARIABLE_NAME=VALUE is resolved to “SET=VARIABLE_NAME=VALUE” by the EnvFile Plugin:
# Input arguments param([string]$buildNumber) "SOURCE_BUILD_NUMBER=$buildNumber" | out-file -encoding ASCII environmentVariables.txt
- get your first hudson job in the stream to run the powershell script:
powershell.exe %WORKSPACE%\dev\source\ReleaseScripts\CreateEnvfile.ps1 %BUILD_NUMBER%
- get your downstream, or child, projects to set the build environment using a file:
- Ensure the build scripts in that job reference your new variable
And hey presto! Your release folders are the same number as the build project. No more confusion!