I am getting started on adding continuous integration to an EC2 project using Jenkins. After the build execution I am deploying the build artifacts in the virtual machines.
Now having some problem with the intermediate files I need to maintain in Jenkins. During the deployment execution my glue ant task is running from the workspace/ folder. At this time I need to create several intermediate files that are this particular build specific.
How to maintain this files? I am aware of the Jenkins directory structure. (Jenkins documentation link on this)
Should I create these files under the builds/[BUILD_ID] folder.
However I do not find a way to get the this folders absolute path. (However I can deduct it from WORKSPACE variable which is available in Jenkins) I already checked Jenkins Set Environment Variables.
Jenkins can store artifacts for each build. You can specify the folders that you want to archive. (However, I simply find it easier to copy all of my required artifacts under a single folder. This way, I cam simply specify that one folder and not worry if I am missing anything.)
If you need these files for deployment based upon the build, I would store them as build artifacts in Jenkins. These are stored in
http://$JENKINS_URL/$JOB_NAME/$BUILD_NUMBER/artifact/...
where...
is the directory structure of your workspace. For example, I tend to build everything in my Java projects undertarget
and store my artifacts under thetarget/archive
folder (Makes it easier to save all of your artifacts if they're under a single folder) If I have a filefoo.txt
stored as an artifact, it's URL would be:I can use
wget
orcurl
to pull down this artifact.You may also decide (if you're using Ant anyway) to zip up or create a tarball of all of your artifacts in one easy to grasp file. That's what I do. Actually, there are usually three files in my
target/archive
directory:DEPLOYMENT_DIRECTIONS.txt
which contains deployment directions.deploy.sh
that is my actual deployment file.In my
DEPLOYMNET_DIRECTIONS.txt
file are these directions:Inside my
build.xml
is something like this:The
<filterset>
replaces the@...@
variables with the environment variables from Jenkins itself. Now, myDEPLOYMENT_DIRECTIONS.txt
look like this:You can cut and paste that line from direction #2 right on the server.
A few notes:
curl
instead ofwget
becausecurl -o
will overwrite an existingdeploy.sh
file. This way, I don't have to worry thatwget
will download the newest onedeploy.sh.2
on me and someone accidentally runs the olderdeploy.sh
from a previous build.base deploy.sh
because I don't have to worry about paths, and setting the executable bit on thedeploy.sh
shell script. It's just easier to tell people to usebash deploy.sh
than specify thechmod u+x
, then do./deploy.sh
.Hope this helps.
By the way, this was designed with three different comfort levels of groups:
DEPLOYMENT_DIRECTIONS.txt
file in the build they want to manually deploy.DEPLOYMENT_DIRECTIONS.txt
file. That's pretty simple to do since it's just downloadingdeploy.sh
and running it.Hope this helps.