jenkins continuous delivery with shared workspace
Asked Answered
C

2

7

Background:

We have one Jenkins job (Production) to build a deliverable every night. We have another job (ProductionPush) that pushes out the deliverable over a proprietary protocol to production machines the next day. This is because some production machines are only available during certain hours during the day (It also gives us a chance to fix any last-minute build breaks). ProductionPush needs access to the deliverable built by the Production job (so it needs access to the same workspace). We have multiple nodes and concurrent builds (and thus unpredictable workspaces) and prefer not to tie the jobs to a fixed node/workspace since resources are somewhat limited.

Questions:

  1. How to make sure both jobs share the same workspace and ensure that ProductionPush runs at a fixed time the next day only if Production succeeds -- without fixing both jobs to run out of the same node/workspace? I know the Parameterized Trigger Plugin might help with some of this but it does not seem to have time delay capability and 12 hours seems too long for a quiet period.

  2. Is sharing the workspace a bad idea?

Cancer answered 28/2, 2013 at 16:26 Comment(0)
C
25

Answer 2: Yes, sharing workspace is a bad idea. There is possibility of file locks. There is the issue of workspace being wiped out. Just don't do it...

Answer 1: What you need is to Archive the artifacts of the build. This way, the artifacts for a particular build (by build number) will always be available, regardless of whether another build is running or not, or what state the workspaces are in

To Archive the artifacts

  • In your build job, under Post-build Actions, select Archive the artifacts
  • Specify what artifacts to archive (you can use a combination of below)
    a) You can archive all: *.*
    b) You can archive a particular file with wildcards: /path/to/file_version*.zip
    c) You can ignore the intermediate directories like: **/file_version*.zip
  • To avoid storage problems with many artifacts, on the top of configuration you can select Discard Old Builds, Click Advanced button, and play around with Days to keep artifacts and Max # of builds to keep with artifacts. Note that these two settings do not control for how long the actual builds are kept (other settings control that)

To access artifacts from Jenkins

  • In the build history, select any previous build you want.
  • In addition to SCM changes and revisions data, you will now have a Build Artifacts link, under which you will find all the artifacts for that particular build.
  • You can also access them with Jenkins' permalinks, for example
    http://JENKINS_URL/job/JOB_NAME/lastSuccessfulBuild/artifact/ and then the name of the artifact.

To access artifacts from another job

I've extensively explained how to access previous artifacts from another deploy job (in your example, ProductionPush) over here:
How to promote a specific build number from another job in Jenkins?

If your requirements are to always deploy latest build to Production, you can skip the configuration of promotion in the above link. Just follow the steps for configuration of the deploy job. Once you have your deploy job, if it is always run at the same time, just configure its Build periodically parameters. Alternatively, you can have yet another job that will trigger the deploy job based on whatever conditions you want.

In either case above, if your Default Selector is set to Latest successful build (as explained in the link above), the latest build will be pushed to Production

Caeoma answered 4/3, 2013 at 18:46 Comment(4)
Thanks, I suspected there was a more standardized way to solve this problem.Cancer
I'm not seeing any options to control automatic deleting of old artifacts. I"m running Jenkins 1.506. Is that functionality in a separate plugin?Cancer
On the job configuration page, check mark Discard Old Builds, then click Advanced... button. You can now control individually how long to keep builds and how long to keep artifactsCaeoma
Great post @Caeoma this is really helpful in my switch from fat builds to pipelinesMarijn
U
0

Not sure archiving artifacts is really a good idea. A staging repository might be better as it enables cross-functional teams to share artifacts across different builds when required by tweaking the Maven settings.xml file.

You really want a deployable (ear/war) as the thing that gets built, tested, then promoted to production once confidence is high with the build.

Use a build number on your deployable (major.minor.buildnumber). This is the thing you promote to production, providing your tests can be relied upon. Don't use a hyphen to separate minor with build number as that forces Maven to perform a lexical comparison... a decimal point will force a numeric comparison which will give you far less headaches.

Also, you didn't mention your target platform, but using the Maven APT/RPM plugin to push an APT/RPM to a APT/YUM repo that's available to a production box (AFTER successful testing!) would be a good fit, as per industry standards?

Uncourtly answered 30/3, 2014 at 0:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.