Changing default location of Quartz job creation - grails

I have the following directory structure in eclipse (groovy project)
grails-app/jobs/File1/ABC/D
grails-app/jobs/File2/DEF/G
I am using the following command to generate Quartz Job :
grails create-job Name_Of_Job
By default it is creating the new job inside
grails-app/jobs/File2/DEF/G/Name_Of_Job
but i want it to be created inside D folder at
gails-app/jobs/File1/ABC/D.
How do i change the location where the Quartz job is created, i tried using
grails create-job c://projectname//Folder//grails-app//jobs//File1//ABC//D//Name_Of_Job
but this does not work it treats file location as name of job

I think you should enter a package name in the grails command (similar to e.g. create-domain-class)
This should work:
grails create-job File1.ABC.D.Name_Of_Job

Related

How to change default wrapper location on Invoke Gradle Script in Jenkins

I have a project with different modules, I want to build the code from a specific module. I'm using "Invoke Gradle Script" in the build step on Jenkins.
By default, the Gradle plugin tries to locate the wrapper executable next to the build script. If it is not there it will look in the workspace root. What I try to do was changing the Wrapper location, to force the build of the correct module.
This is the code structure that I have.
|yurora
|
|---module
|---module
|---wos
| |____src
| |____gradle
| |____wrapper
|
|---module
|---module
This is the value that I have on Wrapper location
${workspace}/yurora/wos
But I get this error FATAL: The Gradle wrapper has not been found in these directories: /var/lib/jenkins/workspace/JenkinsTaskName/yurora/wos.
If I change the value of Wrapper location to
${workspace}/wos
The code builds from the workspace root, and that is what I'm trying to avoid.
What should be the correct path on Wrapper location?
Jenkins configuration
I ended up creating a new git repo with the module that I wanted to build.
It ended up being easier for our time to do it like this, and everything worked out of the box.

Grails Multi-Project: Running a Plugin's custom script

Followed the tutorial on multi-projects
Everything mostly works. Plugin controllers & domain classes load properly in the application. However, a problem occurs when trying to run a Plugin's custom script from the application's grails CLI.
For example:
If you set up the multi-project directory structure like this:
Project Root
Application Directory
Plugin Directory
settings.gradle
And ran this command from the Plugin Directory
grails create-script hello
You'd be able to access the script when running grails from the Plugin Directory, but not the Application's Directory.
Is there a way to get this to work properly? Do I need to use an alternative set up?
Also see Creating a Custom Script in Grails
A conventional grails 3 plugin is different than a plugin within a multi-project. It doesn't seem to be designed to compile a plugin such as grails scaffolding with custom commands.
For this reason, you should package the plugin manually using:
grails package-plugin
grails install
Now in the build.gradle, add this line to dependencies:
compile "<plugin-group>:<plugin-name>:<plugin-version>
Subsituting the appropriate information within the brackets <>.
You can find the plugin-group in the plugin's build.gradle
group "org.grails.plugins"
plugin-name you specified in the grails create-plugin command
grails create-plugin plugin-name
plugin-version is also found in the plugin's build.gradle
version "0.1"

How to run a custom grails command from grails executable jar/war

I'm using grails 3.2.8. I am generating an executable war file from my grails project that has web functionality in it. However, I've also written some custom grails commands that I'd like to be able to run in production (as cron jobs) from an executable jar/war that I build from the same grails project. I can run them in my development environment as "grails run-cmd ...", but I'd like to be able to deploy an executable jar/war file and run the custom command from the executable jar/war. In other words, I want to deploy a war file for web stuff to one server, and I want to deploy an executable jar file for some cron jobs all from a single grails project. I know how build/run the war file--grails makes that easy. However, I really have no idea how to generate an executable jar file from my project that allows me to run my custom grails commands as cron jobs. Can anyone tell me how to do this?
I have found something that seems to work. I've modified the Application.groovy class in my grails project to look like this:
import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
import grails.ui.command.GrailsApplicationContextCommandRunner
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
if (args.length > 0 && args[0] == "run-command") {
// If the first argument is 'run-command', then we just want to run a command as if we were running
// 'grails run-command <grails-custom-command> <args>...'. We are adding the capability of running commands here
// because this is the class that is run from the executable war generated by running 'grails war'. If we just do the same
// thing that grails does to run a command, then the commands seem to execute just fine.
args = args.tail()
// The following code is copied from GrailsApplicationContextCommandRunner.main(). It is what grails does to make
// 'grails run-command' work from the grails console/command line. When upgrading grails, it may be necessary to update
// this code...
def runner = new GrailsApplicationContextCommandRunner(args[0], Application)
runner.run(args)
} else {
GrailsApp.run(Application, args)
}
}
}
I have also changed the dependency in build.gradle for the grails-console dependency from 'console' to 'compile':
compile "org.grails:grails-console" // changed from 'console' dependency since we want to be able to run custom grails commands from the executable jar/war
This is because the GrailsApplicationContextCommandRunner class is in grails-console.
With these changes in place, I can still run the war file with:
java -jar myWarFile.war
However, I am now also able to run my custom commands with the exact same war file like this:
java -jar myWarFile.war run-command my-command <command args>
It seems like there should be a better way to do this, so it would be great if the grails team would comment (and if there isn't a better way, then the grails team should consider adding running custom commands from the executable war file as a grails feature request), but I do seem to be able to run my custom commands from the executable war file this way.

Search for a module in all Jenkins jobs

Is it somehow possible so search for a module within all Jenkins jobs?
Let's say there's the module common-messaging. It's built in Job 1 and Job 2.
When I search for the module name I want both jobs to be shown.
Jenkins store the jobs configuration on disk in XML files. So you can grep the file for whatever XML element is created by the plugin.
create a new job that just have that plugin enabled.
get the XML file: /ci/job/name_of_your_job/config.xml
look for an XML element that correspond to common-messaging, lets say common-messaging.plugin
Then if using a UNIX system:
grep common-messaging.plugin /var/lib/jenkins/jobs/*/config.xml
Windows must have a similar command.
If you have admin access to the server, install the Scriptler plugin (which gives you more easy access to the Groovy console), and fetch and run this shared Scriptler snippet: http://scriptlerweb.appspot.com/script/show/486001

Putting custom values into application.properties

When I build my grails war I would like to put custom properties into my application.properties file?
For example, suppose I have a custom property build.by=tony magoo and I want to add this to my application.properties.
Now this isn't just editing a text file. I am using bamboo to build the wars.
I build several versions of the war and I want to specify particular properites in the grails war command so that get this information from war after it is built.
You can change you file using sed in script task.
Just create new script task and write into inline editor
sed '$ a\ build.by=tony magoo' <path/to/your/apllicaton.properties>
It will add this string to the end of file.
You should execute script task before create war

Resources