Running Groovy command in jenkins - groovy

I want to run a groovy command in Jenkins.For which I have configured groovy through Install automatically.Then I created a free style project and selected Execute groovy script under the build section and then under it I have selected groovy command and have written a simple hello world line.But when I tried executing the job the job history shows pending-Waiting for next available executor and I am unable to build the job.Please help me in identifying the problem and do suggest solution.I am pretty new to Groovy.

You need have at least one executor to run your job.
Do you have any slaves? if yes, check if your slave is okej, otherwise, check if your jenkins have free executor.

Related

How to run a python script in Bamboo server?

I'm new to Devop's field. I wanted to run python script using bamboo server. Can anyone help me with the proper Documentation or any steps?
You have to be much more specific here:
Do you have Bamboo Project/Plan ready?
Do you want to run the script on a remote PC? If so, do you have a Bamboo Agent installed on the PC?
If you have all of the above ready, just create a Job in your Plan. Then create a Task of Builder/Script type. Simplest example of the Script Task would be as on the following screenshot:
bamboo task to run a python script

How to automate a Jenkins task using groovy script which runs on script console

I have groovy script which runs on jenkins script console. My objective here is to automate the process which should run everyday.
Could you guys help me in achieving this task?
There are different ways you can automate it, but you will need to install one of the below plugins:
https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin
https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin
Scriptler plugin is another plugin.
Then,
- Create a Jenkins Job
- Add (system groovy build action or groovy post build action)
- Run and Test
I hope it helps.
Cheers

Using Jenkins to deploy to a Linux server and then run selenium test from a windows server

I am currently trying to deploy a website in PHP to a Linux server using jenkins and then use the same job to run a set of selenium test cases using python on a windows server, I can do both of these things individually but can not find a way to do them both within the same job.
I have tried using the Execute shell setting and then Executing a windows shell but do not know how to tell the job that these are different servers or if this is the correct method.
Is there a reason why you want to do both in the same job?
If you want job B to run only after Job A was completed successfully, You could have job A trigger Job B by using 'Add post-build action' in Job A configuration.

Copy console logs from Unix Jenkins master with Windows slaves to file share

I want to be able to copy the console log from our build jobs into a SMB dropzone we use for all our builds and started looking at implementing it in Groovy. The problem is that the Groovy Postbuild plugin runs on the slave, but our master is a Unix machine so it's unable to find $(JENKINS_HOME)
Is there a plugin for doing this or any sneaky way of making the Groovy postbuild run on master?
The groovy-postbuild plugin provides access to the build and run objects and those can be used to do what you are asking.
def smbShare = new File('/your/smbshare/location/something.log')
smbshare.write( manager.build.getLogFile().text )
manager.build is a wrapper around the following api:
http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html
and there are a couple getLog methods that might be suitable for you.
You'll want to make sure your job user has write access to the SMB share.

Add Jenkins Groovy Postbuild step to all jobs

How can the same Jenkins Groovy Postbuild Plugin step be added to all jobs? We have 50+ jobs, so it is too hard to copy-paste the link to desired groovy code to every job.
I usually do similar mass changes by updating the config.xml of the effected jobs. Every good editoru should have a search and replace function that works on files. use the following workflow.
shut down Jenkins
update job config.xml files
start up Jenkins
There are other possible workflows like the following
1. update job config.xml files
2. reload config
However, with the second option I don't know how it effects if a job is running while you reload a config.
The following script requires the Jenkins Groovy and Groovy postbuild plugins to work. It will add a Jenkins Groovy postbuild publisher to all jobs:
https://gist.github.com/genericpenguin/9ac1b84ed7a145b3b6dd
Change the view from 'All' to some other view for testing. We use it for mass changes and it works fine. Only caveat is that postbuild groovy script must reside on Jenkins master. This can be easily changed in the script if it is short (like a script loader).

Resources