How to find out the the definition of gradle executed task in Jenkins - jenkins

I am new to SCM tool like Jenkins so I may not actually ask the right question.
I find out there is a specific Gradle executed task failed when check the logs of Jenkins.
However, I cannot find out where the Gradle executed task is defined and what is the content of it.
I look up the [CONFIGURE] of Jenkins and then in the [BUILD] section, there is a section called [Invoked Gradle script] and I could see the name (lets call it X here) of executed Gradle task I am looking for.
But I cannot find where X is really defined and what command it actually run, Does anyone has any suggestion? Thanks.

You can try using gradle in verbose mode
gradle -S build
-S, --full-stacktrace
Print out the full (very verbose) stacktrace for any exceptions. See also logging options.
or try using debug mode
-d, --debug
Log in debug mode (includes normal stacktrace).
https://docs.gradle.org/current/userguide/command_line_interface.html

Gradle provides a Domain Specific Language (DSL), for describing builds. This uses the Groovy language to make it easier to describe a build. Each build script of Gradle is encoded using UTF-8, saved offline and named as build.gradle.
By default, Gradle command will invoke Gradle script from build.gradle file.
You can run a Gradle build using the Gradle command. This command looks for a file called build.gradle.
More details here.

Related

Jenkins javadoc plugin doesn't generate documentation

I have installed Jenkins, create a project and configure it.
I run into a problem, Jenkins do everithing great except documentation generating.
Could anyone point me where I have done mistake, and how fix it?
Thank you.
------------------------ New information ----------
Console output:
I have renamed doc to javadoc directory, but it isn't help.
Here is screenshot of javadoc directory contents in console, it is clear that Jenkins plugin didn't generate documentation, but why?
It sounds like you are expecting the Jenkins plugin to produce the documentation. The Jenkins plugin merely copies files from the job's workspace folder to the build's archive area and provides a link to it. If your build steps don't produce Javadoc, then Jenkins won't be able to archive and provide a link to it.
Does your pom file include the maven-javadoc-plugin?
Are your build steps invoking a goal that includes Javadoc generation?
For example, "mvn jar" would compile Java and build the jar but not build the javadocs. Clearly you have executed a goal that executes the tests and provides a code coverage report, but that does not trigger the Javadoc goals either. You would need to make sure your build steps include a javadoc goal - i.e., mvn javadoc:javadoc. The standard goals can be found here: https://maven.apache.org/plugins/maven-javadoc-plugin/plugin-info.html .

Jenkins TestNG plugin does not fetch results from the test-results.xml file

In my project workspace, the test-results.xml file exists inside the target\surefire-reports\testng-results.xml directory. But Jenkins fails to read the XML file and gives below error on console.
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **\target\surefire-reports\testng-results.xml
Did not find any matching files.
To ensure the file isn't too old, I had checked that the test-results.xml (and other files) belong to the latest test run. The Jenkins server is running on Ubuntu 14.04 LTS.
I'm running my tests in this manner: My project root directory has a run_tests.sh script which looks like this:
#!/bin/bash
if [ "$1" = "" ]; then
echo "Please provide a valid suite XML file name."
else
mvn clean
mvn compile
mvn clean test -Dsurefire.suiteXmlFiles="$1"
fi
I just pass the suite XML file name as a parameter to this script in Jenkins (execute shell).
Please help.
I found the solution for this.
Go to Configure of your Job
in General Tab, you may find
Advanced Button, Click on this
Check the check box of "Use custom
workspace", under this you see the Directory text box, here you copy
your Selenium Workspace Folder, for example mine is
"E:\eclipse\eclipse-workspace\WebDriveTest\"
Scroll down the page
under the Post-build Actions, Publish TestNG Results, TestNG XML
report pattern : give like this
"**/target/surefire-reports/testng-results.xml" (check this path in
the same workspace).
I hope this will help you!.
You should be using / instead of \ (since you mentioned that your Jenkins is running on a UNIX box)
Krishnan, in the testng-users Google Group, pointed out that it could be an issue with my Jenkins project workspace, and it was the same.
I changed the default workspace in my Jenkins project.
So I've added the path "$HOME/myWorkspace/myProject/" in my Jenkins project workspace, and "**/target/surefire-reports/testng-results.xml" in my TestNG setting in the same Jenkins project, and it works!
Thank you Krishan for your help.
Please see my answer in another post here, it should be very clear.
In short, it is caused by the current directory was changed to the default Jenkins workspace, you need set your custom workspace in the Job's Config.
I agree with Krishnan Mahadevan usage of '\' instead of '/' while providing the path for TestNG Report also solved my problem.
Extremely important thing to note here:
When providing path for Root POM in the build section '\' is used
C:\Users\harsh\eclipse-workspace\ProjTwo3\pom.xml
When providing path for TestNG XML report pattern in Publish TestNG Result section
'/' is used
C:/Users/harsh/eclipse-workspace/ProjTwo3/target/surefire-reports/testng-results.xml
Console Output:
channel stopped
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern:
C:/Users/harsh/eclipse-workspace/ProjTwo3/target/surefire-reports/testng-results.xml
Saving reports...
Processing 'C:\Users\harsh.jenkins\jobs\MyApplication\builds\12\testng\testng-results.xml'
11.688312% of tests failed, which exceeded threshold of 0%. Marking build as UNSTABLE

Howto set up classpath for System Groovy Script in Jenkins

Documentation for the Groovy Plugin of Jenkins states that
The system groovy script, OTOH, runs inside the Jenkins master's JVM.
Thus it will have access to all the internal objects of Jenkins, so
you can use this to alter the state of Jenkins. It is similar to the
Jenkins Script Console functionality.
Yet I find that I have a groovy script that I can successfully run in Jenkins Script Console but which does NOT run if entered as a "System Groovy Script" on a build configuration. There are compiler errors. Clearly, the Jenkins Script Console is running with a different classpath than the script in my build. But I can't find information on what the default classpath is when running a script for a build or what the classpath is when running from the Script Console, so I might duplicate that for my script.
Also, the plugin offers a classpath entry field for running the script as a file but that option does not exist for entering the script as text.
I can't get my script to work either way.
What am I missing?
I think the answer is that the Script Console auto-imports the whole Jenkins library. That is not the case with the System Groovy Script. So what worked for me was to run the script, and for every compiler error about an unknown class, add an import statement for that class. I learned what packages they were from by looking at Javadocs.
Automating this would be a nice improvement to the plugin.
May be use the grab dependency management to resolve the library to add

Generating WAR using Gradle wrapper in a Grails application

Is it possible to generate a WAR using the Gradle wrapper (ie. gradlew) that comes with a Grails application?
As far as I can tell, after listing all the available tasks, it doesn't seem like it's possible. If not, I wonder why it isn't.
Side note, using it to publish to Artifactory, which is cool IMO.
Update #1
me#workstation ~/ghi
$ ./gradlew help --task assemble
:help
Detailed task information for assemble
Path
:assemble
Type
Task (org.gradle.api.Task)
Description
Assembles the outputs of this project.
Group
build
BUILD SUCCESSFUL
Total time: 6.345 secs
Update #2
I tried the following command: gradlew -Dgrails.env=xxx war
META-INF\grails.build.info shows grails.env=xxx.
Seems like that would work.
The command you're looking for is
./gradlew assemble
and your war will be in build/libs/

Jenkins on Windows using something other than ant

I am looking at using Jenkins on Windows.
I currently have an ant script. It works pretty well. Except for instance, when the build breaks because of a syntax error, I can not see the error in the Jenkins console log.
So I am thinking may be ant is not the best tool for use on Windows.
What do most of you use for Jenkins on Windows?
If it is ant, how do you send the build output, VStudio, to the Jenkins console?
Thanks
Primarily I use Jenkins with maven projects, although you should see the ANT output in the online logs regardless.
What are you building? Are you building Java projects? Ant is what you use. If you are bulding a C project, you should use Make. If you're building a VisualStudio project, you should use msbuild. You use the build tool for your project. Jenkins will execute them without a problem.
Take a look at the build in question. On the left side of the screen, there's a Console output item. Click on that. Is there any output. No matter what tool you use, Jenkins captures the STDOUT and STDERR in that console output. If nothing else, you should see the exact commands Jenkins is executing to checkout and to build your project. Try executing those commands.
Still, you didn't give us much to go on. No idea what you're building or what you're doing with Ant. You didn't state any error, the console output, or even what the Jenkins error log is stating.
Jenkins does two things:
It watches your repository for changes.
Once it detects the changes, it executes the very commands you'd execute to build the project.
Jenkins doesn't care whether you use Ant, Maven, Make, or simply do a del /s/q. Jenkins will simply execute the commands you tell it to execute.
Addendum
It is c, c++, Java and InstallShield. I use ant to do file copy and move, call msdev.exe project. Some Javac calls, InstallShield command line builds..
Jenkins can execute multiple step builds in a single job. After you specify the build step, you can press the Add button to add another build step. There's no reason that all the build steps even have to be of the same type. Just select a "Freestyle" build, and use the right build tools for the job.
There's an optional MSBUILD plugin in Jenkins that should do your MS Build. This should give you the complete output from MSBuild, so you can see any errors.
After you do your MSBuild step, you can create a second build step to run an Ant task to build your InstallShield. After that, you could run another build step to do the copying you need either on the command line or through something like Ant (or Nant.
Whatever the output of the various tools is the output you'll get in the build console.
dev.cmd shows the output and I continue to use ant.

Resources