Grails 2.2.3 - is there a `-y` command line option? - grails

I have a Grails 2.2.3 application and I'm using TeamCity 7.1.3 as my build server. So far, everything was working like a charm until one fine day I decided to update a plugin in my BuildConfig.groovy file.
Locally, I was of course able to update the plugin - but I was asked to confirm the plugin update, which is not a problem if it's locally and I'm the master of the cli, but it is a HUGE PROBLEM if this confirmation dialog pops up at the buildserver where I have no access to the command line during the build step.
Is there a commandline option like -y where I can tell the system to force the y parameter if asked for confirmation? Something like grails refresh-dependencies -y?

You have to specify --non-interactive while issuing commands.
For example: grails compile --non-interactive
To bypass the manual interaction, mainly useful in build servers as in your case.

Related

Automatically Adding New Grails Versions to the Jenkins Grails

Is there a way to configure a new Grails installation automatically? We
usually go into the /config page on our Jenkins server and add a Grails
installation there by hand (we use the automatic download feature, but
that's different).
I thought we may be able to programatically add something like the following
to the com.g2one.hudson.grails.GrailsInstallation.xml file:
<com.g2one.hudson.grails.GrailsInstallation>
<name>grails-2.4.3</name>
<home></home>
<properties>
<hudson.tools.InstallSourceProperty>
<installers>
<com.g2one.hudson.grails.GrailsInstaller>
<id>2.4.3</id>
</com.g2one.hudson.grails.GrailsInstaller>
</installers>
</hudson.tools.InstallSourceProperty>
</properties>
</com.g2one.hudson.grails.GrailsInstallation>
Unfortunately, this does not work, even if we tell Jenkins to reload the
configuration from disk.
-Kevin
The simplest way to install grails version automatically, is to use the grails wrapper.
Go to you project and do
grails wrapper
This installs the wrapper to your project. Check this code in. In Jenkins there should be an option to "use grails wrapper"
Hope that helps
Why don't you use the wrapper? It's pretty simple to install and you can control the grails version for your project from the project.
If you update to another version you don't have to go to Jenkins admin to install the new version. Just upgrade your app, install the new grails-wrapper, commit the changes and push them. Jenkins automatically will use the new version.

Grails fails if started with String parameter

I'm pretty new to the Grails Framework and I'm experiencing some strange behavior. If I use the grails commandline tool this way
grails "-DghprbPullTitle=Title with spaces" clean
grails fails with this error message
| Script 'With' not found, did you mean:
1) IntegrateWith
2) Init
3) CreateUnitTest
Starting grails this way will work
grails "-DghprbPullTitle=Title_without_spaces" clean
Ok one can now say "Then just avoid spaces" The problem is, that this occurs while I'm using Jenkins + Grails Plugin + Pull Request Builder Plugin. The Pull Request Builder Plugin generates some of these parameter with whitespaces.
Any thoughts how I can use grails with such whitespace-containing parameter. Or how I can tell the Pull Request Builder Plugin no to generate such parameter.
Maven on the other hand is able to handle such parameter.
Thanks in advance,
Marco
I ended up using shell builder with grailsw call instead of the Grails plugin.
Ok so it was a bug in the grails commandline tool. It will be fixed in grails 2.4-RC1.
See Grails Issue Tracker
The problem is that Grails Plugin + Pull Request Builder Plugin makes it pass build parameters from PR Builder plugin to grails commands. Those arguments with spaces are not required for build to happen, it's some kind of default in Grails Plugin to pass those parameters along to grails commands.
If Grails Wrapper on Grails Plugin didn't work for you, using Shell commands instead of Grails Plugin worked for me: it avoids parameters with space and makes GitHub notifications to work. It's worse for grails installations maintenance, but at least it's an alternative.
I submitted a PR https://github.com/jenkinsci/grails-plugin/pull/12 to work around this by suppressing the -D build environment variables.
I am using the Github pull request builder plugin https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin to run test-app and was running into the same issues as others. I am not using any of the variables that the ghprb plugin passes in so I added an option to suppress -D build environment variables. When this option is checked none of the -D variables are passed to grails allowing the build with grails plugin to run the targets as expected.
If you want to test it out to see if it works for you, you can download it from here http://jmoses.co/data/grails.hpi and install it manually How to install a plugin in Jenkins manually?

How to install plugins in jenkins, with the help of jenkins remote access API?

I would like to know, how can I install a plugin to Jenkins, using the Jenkins Remote
access API?
I found a way to install using jenkins CLI. But I need to know how to do the same using API.
I tried using jenkins-python library. But I did not find any way to
install plugin there.
Send (HTTP POST) the following xml data (with your plugin-id#version) to Jenkins plugin manager. Check out my jenkins install plugin script on gist.
This HTTP POST request install jenkins git plugin 2.0.
curl -X POST -d '<jenkins><install plugin="git#2.0" /></jenkins>' --header 'Content-Type: text/xml' http://localhost:8080/pluginManager/installNecessaryPlugins
Some plugins are hard to update on the file system because others depend on it (credentials is one example). For such plugins it is only possible to update them using the web interface.
Jenkins frontend has a page under 'Manage Jenkins' -> 'Manage Plugins'. Under the 'Advanced' tab is a form to 'uploadPlugin'. It allows web automation with curl, you might need to add authentication.
curl -i -F file=#pluginfilename.hpi http://jenkinshost/jenkins/pluginManager/uploadPlugin
In addition to the methods already mentioned (I personally used the "curl uploadPlugin" one provided by #bbaassssiiee), you need to consider that if you use pluginManager Jenkins will try to load your plugin dinamically, but in case you need to restart Jenkins to initialize the plugin properly (this was my case), you should add:
curl -kX POST https://${JENKINS_URL}/safeRestart
In case you copy the plugin directly to jenkins/plugin, the restart is mandatory for the plugin to be loaded.
As suggested by malenkiy_scot, we can create a job and use the Jenkins CLI. Here is the secret way I do for my automation in installing plugins. Jenkins plugins are available in the Jenkins mirror here: http://updates.jenkins-ci.org/latest This link might not list anything but you can download the plugin if you know the name of the plugin. For example, if you want to download the skype-notifier plugin, you can download it from http://updates.jenkins-ci.org/latest/skype-notifier.hpi The generic URL is "http://updates.jenkins-ci.org/latest/.hpi"
After downloading that plugin, it should go to the "plugins" directory in Jenkins home on the server. For linux machine, it will most likely be in "/var/lib/jenkins/plugins". Simple example
wget http://updates.jenkins-ci.org/latest/skype-notifier.hpi
mv skype-notifier.hpi /var/lib/jenkins/plugins
There are two things to note here:
If the plugin has any dependencies, those will not be installed by default. If you know what other plugins are required, those can be installed the same way. A bit of manual process is required here. But if a same set of plugins are required, the dependency can be resolved just once and script can be written to download and move them to the Jenkins home.
Downloaded plugins cannot be used right away. A reload of Jenkins is required.
After a lot of blood sweat and tears my suggested solution is:
Download the hpi files (plugin and dependencies) using plugin-installation-manager-tool
(requires java) or install-plugins.sh (requires bash only, but is officially deprecated, though still working 09/2021)
Note: Both are also contained in official docker image (see also Offline Installations)
Then install all downloaded files via
curl -i -F file=#plugin.hpi http://${JENKINS_URL}/pluginManager/uploadPlugin
Why?
POSTing to /pluginManager/installNecessaryPlugins always installs latest version (known bug or feature?) and seems to only install the requested plugin without proper dependency handling.
Simple example
Requires install-plugins.sh and its dependency jenkins-support from jenkinsci/docker.
You have do adapt install-plugins.sh line 27 to point to your jenkins-support file, e.g.
. jenkins-support if you have everything in one folder and execute it from there.
pluginFolder=$(mktemp -d)
# Download plugins
JENKINS_UC=https://updates.jenkins.io REF="${pluginFolder}" \
install-plugins.sh \
docker-workflow:1.26 docker-plugin:1.2.2
# add more plugins in here, pass a bash array or load from file
# (see Real-life example bellow)
# Install all downloaded plugin files via HTTP
for pluginFile in "${pluginFolder}/plugins"/*; do
curl -i -F "file=#${pluginFile}" http://${JENKINS_URL}/pluginManager/uploadPlugin
done
Real-life example
Taken from cloudogu/gitops-playground.
download-plugins.sh - loads all plugins declared in plugins.txt using install-plugins.sh to a directory passed as parameter.
init-jenkins.sh calls download-plugins.sh, then installs the plugins using jenkins-REST-client.sh
I do not think this is possible. However, as a workaround you may consider creating a job that would install plugins via Jenkins CLI; you then can invoke that job via the API with appropriate parameters.

Grails and hudson plugin issue

I'm developing my first project in Grails framework. I'm using Spring Security Core plugin. On my machine, on newest IntelliJ Idea everything works fine. I can run, test and so on with no problems.
I have a remote machine with subversion where I upload my code and Hudson with Grails Plugin. Target which I call on my hudson builds is:
"test-app --non-interactive"
When I run build, everything goes fine - plugins are downloaded and then, bam!
Resolving plugin JAR dependencies ...
:: UNRESOLVED DEPENDENCIES :: ::::::::::::::::::::::::::::::
:: org.springframework#org.springframework.test;3.0.5.RELEASE: configuration not found in org.springframework#org.springframework.test;3.0.5.RELEASE: 'master'. It was required from org.grails.internal#League;0.1 test
Here I put whole output from Hudson Console of this project build.
That looks like a dependency issue with the Mail plugin, try going back to a non-snaphot version. I think 1.0 will be out shortly but see if 0.9 works.
Grails will automatically install the plugins it needs, you don't need to do anything manual on the build server.
You have to install the plugin of the remote machine. Because the plugins are not included in the code. The plugin will be installed under your_home/.grails/grails_version/plugins (or project/your_project).

Installing Nimble for Grails

I came across Nimble yesterday, but couldn't get past Step 1, configuring BuildConfig.groovy to find the Nimble's remote repository.
My BuildConfig.groovy file is one line:
grails.plugin.repos.discovery.intient="http://intient.com/downloads/grails/
Here is the message I get when running grails install-plugin nimble 0.2:
Welcome to Grails 1.1.1 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /opt/dev/sdks/grails-1.1.1
Base Directory: /home/wraith/dev/source/demo
Running script /opt/dev/sdks/grails-1.1.1/scripts/InstallPlugin.groovy
Environment set to development
No authentication for svn repo at intient ...
Reading remote plugin list ...
Reading remote plugin list ...
Reading remote plugin list ...
Plugin 'nimble' was not found in repository. If it is not stored in a configured repository you will need to install it manually. Type 'grails list-plugins' to find out what plugins are available.
This is the first time I have tried to install a plugin not in the official repository. What is the best way to narrow down if it is a problem at Intient.com or with my configuration?
Follow these instructions with the following modifications:
Step 1 is correct
Instead of using the remote repository, download the zipped plugin
Move the plugin to ~/dev/plugins
grails install-plugin ~/dev/plugins/grails-nimble-0.2.zip
Steps 3-5 are correct
We were performing some maintenance on intient.com and the load balancer wasn't providing this content for the last 12 hours or so (oops!).
Should be sorted now but the steps Wraith Monster gave above work for a manual install as well.
Once Grails 1.2 proper hits Nimble will be part of the official plugin repo and we won't need to worry about this at all.
you could always download the zip file for the plugin and install it manually
Download source code from http://github.com/intient/nimble
Unzip under your plugins directory of your project (usually under ${USER_HOME}/.grails/<grails-version>/projects/<myproject>/plugins)
Rename the extracted folder into "nimble-0.2"
Remove from BuildConfig the line grails.plugin.repos.discovery.intient="http://intient.com/downloads/grails/"
Edit the file application.properties of your project and add the line plugins.nimble=0.2
If not installed under your project, you should install the plugins : shiro (version 1.0-SNAPSHOT at least) and mail (>0.6). (run command grails install-plugin <pluginName> <version>)
Start directly from Step 3
It should work (at least, it worked for me). Good luck

Resources