Control when to execute a windows batch command in hudson - continuous-integration

I currently use Hudson CI and would like to know if it's possible to conditionally execute a build step depending on if there are changes in the build or not. We currently have an automatic build process that is scheduled to run daily, and the batch command automatically tags each build. However, I don't need it to tag a build if there are no changes.
Thanks

If you want a periodic build that only runs if there has been an SCM change you can switch from a periodic build trigger to a "Poll SCM" trigger, with the SCM polling schedule set to the same cron pattern as your existing build.

Related

Schedule Fortnightly Build in Bamboo

I'm looking at automating the bamboo release in my team currently it is manually triggered. Releases happen every second Wednesday and a custom variable is set to signify this. If the variable is present an automatic merge to the release branch is triggered.
There are two issues I am running in to
There doesn't seem to be a way to schedule a fortnightly build in bamboo.
I don't see a way set a custom variable with a scheduled build. I just need some sort of flag to say this was the weekly build and not the automated build that happens on check in.
There are a lot of builds so I don't want to make an additional build plan for each plan.
It's possible to create Schedule trigger with cron expression. Try to use expression which executes your build on 1st and 16th day of month
1 1 11 1,16 * ?
There is no way to set variable value for scheduled builds
a) There doesn't seem to be a way to schedule a fortnightly build in bamboo.
You can use cron job expression for scheduling fortnightly builds.
b) I don't see a way set a custom variable with a scheduled build. I just need some sort of flag to say this was the weekly build and not the automated build that happens on check in.
You must be having some admin user which runs automatically triggered
bamboo builds. You can use Bamboo variable
{bamboo.ManualBuildTriggerReason.userName}. If this variable name is
equal to Bamboo admin user name then this build was triggered at
scheduled time. otherwise it was triggered by user/developer.

Jenkins Conditional Deployment

I am using Jenkins to create nightly builds and deploy them to my maven repository. In order to reduce the daily bandwidth for developers I want to change the deployment logic so that it's only deployed if changes with reference to our latest deployment are detected.
I found some plugins that seem to be suitable, but since I'm not too involved into the Jenkins use-ability I wanted to ask if there is an "easy" way to implement this?
I thought about some simple test before executing the deployment process:
Check if there are changes made within the project code or the dependencies
=> NO: then nothing should be deployed
=> YES: deploy the new version
I just stumpled over the Conditional BuildStep Plugin. But I'm not sure if this plugin fits best for our approach. I don't want to mess up the whole configuration.
FYI: I am using Jenkins 1.608, Tortoise SVN, and the deploy-Plugin 1.1
Every answer and help is highly appreciated!
Setup your job to run nightly (current configuration)
Setup a conditional build step (shell or batch, depends on your OS) that will check the revision number in repository and compare to current revision number in workspace.
If not higher, quit the build.
If higher, continue build as usual
Edit:
To avoid the build even being triggered, here is a theoretical solution.
Install Poll SCM Now plugin, this will add a "poll now" button to the job, that polls SCM for changes. If changes found, a build is triggered, if not, nothing happens.
Configure the polling permissions to anonymous users (else you'd need to implement login/token in next steps)
Configure the job to poll SCM infrequently (like once a year)
Configure a cron job (or a scheduled task in Windows) for a nightly schedule
Have that cron/task do a curl or wget to http://JENKINS_URL/JOB_URL/poll

Consecutive Job Execution in Hudson

We are using Hudson for our builds and deploys. Currently we have four main jobs: BUILD, DEPLOY-DEV, DEPLOY-TEST, and DEPLOY-PROD.
The BUILD job is parameterized, so we can assign new version numbers and augment them with the BUILD_NUMBER managed by Hudson. This works very well. We also have a "nightlybuild" parameter that defaults to false. Our intention is to only set this via another Hudson job.
We are trying to have an automated NIGHTLY-BUILD job that first calls our BUILD job with the "nightlybuild" parameter set and once that is successful, call the DEPLOY-DEV job. We also want to call out to a SONAR job to analyze the code, but for this question, the 2-step solution is sufficient.
For the NIGHTLY-BUILD job, the only way to call a parameterized job that I can figure out is the post-build action of "Trigger parameterized build on other projects". I can't trigger off of the BUILD job directly because the "nightlybuild" default is false and I also don't want to trigger off any manula builds. I also have a NIGHTLY-DEPLOY that has a build trigger of "Build after other projects are built" on NIGHTLY-BUILD. Since these are both ultimately post build actions they trigger at the same time instead of consecutively.
Started by user anonymous
Triggering a new build of BUILD #49
Triggering a new build of NIGHTLY-DEPLOY #3
Triggering a new build of NIGHTTY-SONAR #3
[DEBUG] Skipping watched dependency update; build not configured with trigger: NIGHTLY-BUILD #5
Finished: SUCCESS
When I start the build, it completes in a few seconds and starts the BUILD and DEPLOY concurrently, so as a new version is building, the old version is deploying. Not what I want.
I looked at and downloaded the "Build Pipeline Plugin", but it looks like it just relies on the same post build actions for the automatic transitions and adds new functionality for manual transitions.
Does anyone have any suggestions on how to resolve this issue?
Use Parameterized Trigger plugin as a build step, not post-build step. Then it has an option to wait for the downstream build to complete.
Note: this works with Jenkins, I can't guarantee that this option exists in the Hudson version of the plugin.

Disable scheduling another build if previous one is running in Jenkins

I have a build that polls SVN and checks for changes every hour. if it finds changes it starts building.
Right now if it sees changes and a previous build (from the same job) is running, it will queue the build and start it when the previous build finishes.
Is there an option to disable the queuing of multiple builds ?
Here's a workaround: let one job (Trigger) do the polling and then call the main job (MainJob) that will do the updating and building. You can even use the Parameterized Trigger Plugin to pass the SVN revisions and URIs. You then check off Block build when downstream project is building in Trigger.
To propagate change-sets from Trigger to MainJob use BlameSubversion Plugin.
(BTW, here's a neat trick: Trigger does not have to check out the whole SVN tree, you can check it out by hand with --set-depth empty in the working copy of Trigger).

Schedule specific build target in Jenkins?

The group that I work in has standardized on Jenkins for Continuous Integration builds. Code check-in triggers a standard build, Cobertura analysis and publish to an Artifactory SNAPSHOT repo. I've just finished adding a new target to the master build file that'll kick off a Sonar run but I don't want that running on every check-in.
Is there a way to schedule a nightly build of a specific build target in Jenkins? Jenkins obviously facilitates scheduled builds but it'll run the project's regular build every time. I'd like to be able to schedule the Sonar build target to run nightly.
I could, of course, create a separate Jenkins project just to run the Sonar target on a schedule but I'm trying to avoid that if I can. Our Jenkins server already has several hundred builds on it; doubling that for the sake of scheduling nightly builds isn't very desirable. I looked for a Jenkins plug-in that might facilitate this but I couldn't find anything. Any suggestions?
Here's one way to do it, if you are ok with triggering the build using cron or some other scheduling tool:
Make the build parameterized, and use a parameter in your build file to decide if the Sonar build target should run or not.
Trigger the build remotely by HTTP POST:ing the parameter values as a form to http://[jenkins-host]/jobs/[jobname]/buildWithParameters. Depending on your Jenkins version and configuration, you might need to add an Authentication Token and include this in your url.
Authenticate your POST using a username and password.
wget --auth-no-challenge --http-user=USERNAME --http-password=PASSWORD "https://[jenkins-host]/job/[jobname]/buildWithParameters?token=<token defined in job configuration>&<param>=<value>&<param2>=<value2>"
I am also looking for a solution for this. My current solution in my mind is to create 2 triggers in the regular build, one is the nightly build, another one is Polling SCM
In the sonar plugin configuration, it has the options to skip the builds triggered by the SCM change. Therefore, only the nightly build will start a sonar analysis.
I didn't get a chance to test it now, but I suppose this will work.
Updated on 12/19/2011
The above solution doesn't work if the sonar analysis is invoked as a standalone build step. To make the sonar analysis run conditionally, you could use the following 2 plugins:
Conditional BuildStep Plugin - this allows the sonar analysis to be run conditionally
Jenkins Environment Injector Plug-in - this allows you to inject the variables to indicate how the build is triggered.

Resources