jenkins enable maven command line - maven

I want to setup jenkins using the command-line only. I am successfully able to install plugins and configure jobs. So i've installed the maven-plugin using jenkins-cli but want to be able to configure it to say "Automatically install maven latest version" so that when the user triggers a build it will automatically go download maven and then use it just like it does using the GUI.
Any advice on how i can do this piece of configuration on the command-line (or scripted ideally) please?

This option is not and should never be available for the reason that it destroys the concept of reproducible builds.
Changing the maven version deliberately may break the build at some future time for no apparent reason and will definitely startle your users then.
Please avoid this situation.

Why not use maven wrapper instead, this way each project configures specifically which version of maven it needs and automatically downloads it.
https://github.com/takari/maven-wrapper
https://github.com/takari/maven-wrapper/blob/master/README.md

Related

How to get Jenkins repository server to host only stable builds?

I have Jenkins version 2.7.1 running on a Windows 7 machine. It is successfully pulling code from a subversion repository and running tests. I have the test jobs set up for the development branch of each project only.
We periodically make stable releases of the projects in jar files with version numbers. I would like to have Jenkins be the repository manager for those stable releases. These are made by hand - There is no Jenkins job making or testing stable releases. The projects do use Maven.
Each stable build is tagged in the subversion repository, so it could be made again on demand if needed.
I downloaded the Maven repository server hoping to make this fit the purpose. I read the documentation that's provided, but it's pretty terse. As I understand it and have it configured now, this appears to have a couple of issues:
If I go to jenkins-ip/plugin/repository/project, it has made directories there that expose the names of all of my projects, which seems undesirable. (Here jenkins-ip is the IP where I access Jenkins on my local network.)
On the other hand, there's nothing but empty directories under these projects, so they're currently useless.
These projects all correspond to the continuous testing of the development branch. There's no apparent way to get the stable builds into the hierarchy. (It doesn't seem efficient to create a job for each stable release...)
Is there anyway to get Jenkins (with this plugin or through another method) to be the repository manager just for the stable builds? I know that I can start a different repository manager like archiva, but it would be ideal to use Jenkins since it's already running and it seems to claim capability for this function now.
To use Maven repository server you have to build the project on Jenkins.
Then the plugin will expose all archived artifacts as maven repo.
Note you need to use a "Maven project" type for it to work (freestyle is not supported)
There are several plugins that will help you manage building from multiple tags, however not all of them work with "Maven project" type.
You could also try Jenkins pipeline (previously "Workflow") or the Job-DSL plugin.
A simplest solution would be to have a build parameter specify the tag name (then checkout e.g. ^/tags/projectname/${tagParam}), but you have to figure out how to trigger the job then.

Is there a reason to install Gradle instead of using gradlew?

The recommended way to use Gradle is through the Gradle Wrapper, (gradlew), which is checked into version control of the project.
My question is: is there any reason to install Gradle myself from http://www.gradle.org/downloads instead of using the wrapper everywhere? (and copying the wrapper to new projects from an older project)
If You work with gradle occasionally (not with one particular project (or a set of projects)) it's very useful to have gradle installed on command line. Then You can easily create a script and check if it works fine. With gradle installed on CL it's very easy and fast (no need to download the whole distribution every time). Beside this one particular use case nothing else comes to my head.
P.S. There's a great tool for gradle (and other tools) version management: GVM.

maven plugin detect hudson

I'm writing a plugin for maven and I want find out, if it runs on hudson. Then I want to know which user triggered the build.
Is there an API (#component) that provides access to this?
Usually during a run in Hudson some environment variables exists like JOB_ID etc. which you can use to detect if running in Hudson.

Is it possible on TeamCity to build a module against all agents when a VCS Trigger is met?

I would like a module to be run by all agents when a VCS trigger condition is met.
Is this possible?
One way you can do this is by adding a Schedule Trigger which has an option to run on all agents.
Having looked into it, as far as I can see, not directly,
the behaviour could potentially be achieved by using the command line remote runner plugin,(http://confluence.jetbrains.net/display/TW/Command+Line+Remote+Run+Tool) through a seperate build configuration linked to the VCS to detect the changes, calling the Remote Run tool from a command line build step to build the project on each required agent.
Further research into the Command Line Remote Run tool would be required to confirm this is possible.
There may also be some functionality allowing this in the REST API, although my look through the documentation didn't show anything up.
Have you had much luck working on alternative solutions?
I've created a build configuration to update our source managed third party referenced assemblies directory and this is a snapshot dependency on most if not all build configurations. When I update this directory with a new or more recent assembly, I'll too would like this configuration to be run on all build agents.
At the moment, I've simply duplicated the configuration and bound each to a specific agent. It adds management overhead, but has temporarily resolved the issue.
You could install this plugin and specify the list of agent names and it will run once per "value" in the matrix.
https://github.com/presidentio/teamcity-matrix-build-plugin

Template plugin for Jenkins

Is there any plugin available in Jenkins which allows you to reuse shared configuration across the jobs.. e.g I can define a template for Continuous Integration and other template for Running Tests and create multiple jobs from these template for different branches.
I know template plugin is available in Enterprise Jenkins but is there something similar available for jenkins open source?
I am looking for something similar to
here
I have found ez-templates plugin to behave well for Jobs templating. It is very young project and you will have to build it by yourself (which is very simple, see below), but still it is much more powerful than Template Project Plugin as it supports any types of jobs.
How to build:
Install Maven 3
Clone/download the ez-templates git repo
Run 'mvn install' from the ez-templates checkout folder
Once build is ready go to the 'target' folder and find the ez-templates.hpi which is self contained plugin binary.
How about the Template Project Plugin?
The Job Generator Plugin was released after this question was asked, which may fulfil some people's needs.
Unfortunately the Template Project Plugin still has some issues, particularly in that it lacks support for job parameters.
We use the Jenkins job builder to automate creation and management of our jenkins jobs. It was basically built to allowing share configurations across jobs so you can easily create the same jobs with multiple configurations. Check it out: http://docs.openstack.org/infra/jenkins-job-builder
You can use the Copy Project Link plugin. https://wiki.jenkins-ci.org/display/JENKINS/Copy+project+link+plugin
What I have done is to create a disabled (dummy) pre-configured job and when I want to create another one with the same configuration I just copied by using this plugin.

Resources