Queue build on specific agent based on custom parameter - tfs

I have a build definition with a custom process parameter. If set to true, I'd like the build to queue up on a specific agent, essentially overriding any agent name that's set in the definition. I'd rather not use tags because I don't think they'll be used properly, plus this seems more dynamic in nature. I'm thinking this could be done in the build process template somehow. Just not sure how to accomplish it.

You can customize the build process template to look at your custom workflow argument, and change the value of the AgentSettings.Name prior to the Run On Agent activity.

Related

Jenkins plugin for triggering build from Dashboard with input argument?

We have a project with more than 100k regression tests and therefore we'd like to have the alternative to manually trigger and check if a Test Suite(s) have been broken due to a specific change instead of running all tests.
I have a build project configured in a way that everything is in place and it expects only parameter value to be appended i.e. -DwildcardSuites=<Suite Name Pattern>.
Is there a Jenkins plugin that would allow entering an input text to be appended to the Goals and options and that corresponds to the specific Suite pattern we'd like to run?
Extensible Choice? https://wiki.jenkins-ci.org/display/JENKINS/Extensible+Choice+Parameter+plugin
There are a few similar plugins, they tend to have one or more of "Choice", "Active" and "Dynamic" in the name.

Jenkins plugin code that should excute before any kind of job is run in Jenkins

I am new to Jenkins plugin development. M trying to write a plugin that should be executed before any Multi configuration type job runs in Jenkins.
In this plugin I want to write rules that will check what configuration parameters user has selected while submitting the job, based on selected parameters, I want to decide whether to allow the job to run or to restrict it.
User should be shown reason as to why that job cannot be run in the Console Output.
Does anyone have any ideas which class I need to extend or which interface I need to implement in order to get a hook into Jenkins job run?
You could look at the Matrix Execution Strategy which allows for a groovy script to select which matrix combinations to run. I would think if your script threw an exception it would stop the build.
For background, the multi configuration projects run a control job (or flyweight) which runs the SCM phase then starts all the actual combinations. This plugin runs after the flyweight SCM checkout.
If nothing else, this will give you a working plugin to start from
Disclaimer: I wrote this plugin
Blocked queue job plugin was what I needed
Out of the box that plugin supports two ways to block the jobs -
Based on the result of last run of another project.
Based on result of last run of the current project
In that plugin the BlockQueueItemTaskDispatcher.java extends Jenkin's QueueTaskDispatcher providing us a hook into Jenkins logic to allow or block the jobs present in the queue from running.
I used this plugin as a starting point for developing a new plugin that allows us to restrict project based on parameters selected and the current time. Ultimate goal is to restrict production migrations from running during the day.
Overriding the isBlocked() method of QueueTaskDispatcher gave access to hudson.model.Queue.Item instance as an argument to me. Then I used the Item instance's getParams method to get access to build parameters selected by the user at runtime. Parsed the lifecyle value from it. Checked the current time. If lifecycle was Production and current time was day time then restricted the job by returning non null CauseOfBlockage from isBlocked() method. If that condition was false, then returnedCauseOfBlockage as null allowing the queued job to run.

Jenkins to trigger another build/project dynamically

Is there a way in Jenkins to trigger another build/project dynamically based on a parameter value in parent project?
The reason for this is that I have 100's of projects and I don't want to use pipeline/conditional post build plugins to link all jobs.
I know of a way using REST API but trying to find is there a way to trigger a single project from those 100?
Easy with Pipeline Plugin. Just define your parameter (say MY_DOWNSTREAM_JOB) and use it inside the groovy script definition:
build MY_DOWNSTREAM_JOB

Generic jenkins jobs

I wonder, if it is possible to create generic parametric jobs ready to copy where the only post copy action is to redefine its parameters.
During my investigation I find out that:
- I can use parameters in svn path definition
- I can define the flow of builds using *Build Flow Plugin*
However I cannot force Jenkins to use parameters inside job names definition for promotion process. Is any way to achieve that?
Since I create sometimes branches from master I would like to copy the whole configuration of jobs but only one difference most times is that in the job name definition I replace master with branch name.
Why it not possible to use a parameter as the branch name?
Then when you start to build the job, you can input the parameters based on the branch you want to build.
Or find some way to get the branch info and inject it.
For example, we have one common job, which will monitor maybe 20 projects, if any of those job was merged into git, our gerrit trigger plugin will start to work, and all of job name, and branch is got dynamically from parameters.
Hope this works for you.

How to run parametrized build after commit to repository?

I have parametrized build job in Jenkins. It has configured SCM polling and the build job is started after new commit.
Parameters for this build job are location profiles defined in main pom.xml. Count of these profiles is static and persistent. So after every commit I need to build a project for the same profiles. One profile is started for one build.
It is able for manual triggering when I write profile name and start the build job. But after new commit this build job is started without parameters. So is there any way how to define list of parameters for build job - one parameter per one build.
An SCM change will trigger a related Jenkins job. Once. That's it.
When that job is triggered, and is configured with parameters, it does have default parameters.
For string parameters, it's the default value entered in configuration page (if you haven't entered one, the default is just that: none).
For single choice-style parameters, it's the top-most value.
For multi choice-style parameters, again, unless a default is provided in configuration, it's nothing.
If what you want is to trigger multiple runs of the same build for the same SCM change, then you've configured your jobs wrong.
Either create a matrix job, and configure an axis for every "profile" as you call it.
Or create multiple jobs, and chain them, so that first is triggered by SCM change, and the rest are triggered in sequence
If you only want to specify one default string that should be picked up while building using Poll SCM feature, then you should try using the following method:
Select the following options in Extended Choice Parameter:
In Simple Parameter Types section, go for Single Select in Parameter Type
Instead of Choose Source for Value, go for Choose Source for Default Value. Now enable the radio-button named Default Value. Enter whatever string you want to specify. Build will pick-up the given string as the default one.
Hopefully, it should work. At least, it works when i use Build periodically option. :)

Resources