configure jenkinsfile to allow remote trigger for the job - jenkins-pipeline

How can I configure my jenkinsfile to allow for remote triggers in the job.
The option is available if I try to configure a regular job, as shown in the image below, but I could not figure out a way for the same via jenkinsfile.
can someone help for the same.
Update:
Trigger option available under jenkins' "pipeline syntax" help.

just add 'authenticationToken('token_name')' in the pipelineJob closure. It worked for me. See documentation:
https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.jobs.WorkflowJob.authenticationToken

Related

Ansible tower cannot see playbook in drop down list

I am looking for a way to trigger a git pull or a refresh from source control within ansible tower. The situation is that I have added a playbook in source control, however I cannot see it within ansible tower.
Is there a way to trigger a refresh or a git pull ?
Thanks in advance.
I just realised that if the template job is executed, if you go back to the template it now shows any newly added playbook.
What it looks like is that when a template job is executed, it forces a git pull or a refresh behind the scenes.
In order to find an updated list of playbooks available to your project you need to refresh your project. This also happens when you run the template job which is why you kind of solved it while running the job.

create different types of job in jenkins

How can I create different types of Jenkins projects like Maven, Multi configuration etc. and configures them using groovy script that can be run on Jenkins script console? or is there any Jenkins-cli command available in order to achieve this.
In case you know any other approach apart from this please let me know. Thanks in advance.
First - You need the appropriate plugins for the different job types (like the Maven plugin).
If you'll read a bit about the CLI (JenkinsMaster:port/cli/) you can see that you have many actions you can do. One of them is to create a job:
java -jar jenkins-cli.jar -s http://JenkinsMaster:Port/ create-job NAME
You will need to define a job configuration file (a simple xml file) to add using the CLI.
I would suggest creating a Maven job for example, go to your $JENKINS_HOME/jobs folder and see how the xml file is written to better understand what it is you need to do.
And I would also suggest to try and read about Jenkins and how jobs are configured and work. I will add links to great tutorials if needed - comment if you intend to learn and interested.

How to trigger maven specific job in Jenkins with Gerrit

I'm currently using Jenkins(1.451) and the Gerrit Trigger(2.3.1) to launch builds from Gerrit in order to verify code.
This is working fine as long as the project in Jenkins is configured as a "Free style" project. However, I'm currently setting up a new build pipeline where I'm using the "Build a maven2/3 project" option in order to take advantage of maven specific properties which I can't get from the "Free style" option. For some reason, Jenkins doesn't seem to trigger builds using this option. Nothing at all happens when I submit code to Gerrit which under normal circumstances should be picked up. I'm actually wondering if the Gerrit trigger is meant to work with Jenkins projects configured as a maven2/3 job or maybe it is the case that I can only use the Free style option in order to do this.ge
Could anyone confirm if this is the case?
Yes this will work. I suspect you might have some authentication issues that causes your jobs not to be triggered.
Check you sshd_log in the gerrit config folder to see if there are any jenkins logins that result in immediate LOGOUT. I my case I forgot to add Stream Events rights to the Non-Interactive Users under All-Projects and this caused some strange behavior.
This was the message I saw 3x per second in my sshd_log:
jenkins a/1000002 gerrit.stream-events 0ms 0ms not-admin
See here for more details

Cruisecontrol actions after a successful build?

I am using cruisecontrol (phpCruiseControl to be precise) as a CI server and have my build script running on an automated basis. Is there anyway to add tasks to the cruisecontrol config script to be actions upon a successful build?
Thanks
I only have experience with the Java based CruiseControl so I don't really know if phpCruiseControl is any different but for the "common" CruiseControl you can define in the configuration file (usually config.xml) you have the option of adding "publishers".
These run after the build completed.
In reply to your question, you need to add to the configuration an <onsuccess> element under the publishers section in it you can call whatever publisher you like.
read the documentation for the explanation.
Basically you want something like this:
<cruisecontrol>
<project>
<publishers>
<onsuccess>
<antpublisher buildfile="myTasks.xml">
...

Hudson build on URL token

I configured a hudson instance and have created jobs. While creating builds, I was able to see this option "Trigger the build by accessing this URL + SecretTOKEN" option. Now, I am unable to see that for any new jobs I create. Am I missing some setting or a configuration? The only change I made was running the servlet container from Root to a regular user.
In my Hudson (1.349) when creating a new job, there's an option under Build Triggers called Trigger Builds Remotely (e.g. from scripts), which when selected allows you to enter an Authentication Token (which has the descriptive text from your question).
I'm not aware of any system configuration that disables this. It doesn't sound like a Hudson user permissions problem if you can have permissions to create/edit jobs.
What appears under Build Triggers when you create a new job?
I had the same problem with the missing Trigger Builds Remotely option. The fix in my case was to enable security in the main Hudson configuration (with Anyone can do anything selected)

Resources