Setting up Rake with Jenkins? - ruby

How can I report to Jenkins on individual task or steps of a rake-file?
I want as much info as possible about each sub task.

Related

MyTask getting unwantedly executed when building

I want to print a link to our team's documentation if the developer types:
gradle help
using this task:
task help {
println "Full Documentation"
println "https://confluence.org.com/Help"
}
which it does.
However, I do not want it to execute when I run:
gradle build
Is the help task supposed to run whenever build is run? If not, why does this task get executed? As you can tell, my understanding of gradle is limited.
You are effectively overriding the built-in help task that Gradle provides. As a result, other tasks or plugins in your project may be referencing that task already or other parts in the overall Gradle build rely or use help in some fashion.
To summarize, do not override Gradle built-in tasks otherwise it will lead to unexpected/unintended consequences.
To fix, rename your task to something other than help.

Is there a way to list all jobs of Jenkins in a shell script that will be run as a Jenkins job

I am writing shell commands as a build step for Jenkins job
Is there a way to write a script that list all Jenkins jobs
Please check the below reference. This seems to answer your question
Ref: Jenkins CLI List-Jobs with folders

ant Maven task : redirecting output with spawn=true

a rather clear question here.
I have to launch a Maven job, which is to be run in parallel with ant and it's okay if the job outlives the ant process, hence spawn="true".
I have to see the job output at the end of the Maven build like build is successful or got failure. This is perfectly achievable for spawn="false", but I am kinda out of luck having spawn"=true".
So, is there any solution for this? Please help me out

Execute Shell Script after post build in Jenkins

I am trying to execute a shell script if either the build pass or fails after post-build in Jenkins. I cannot see this option in post build to execute some shell script except for running a target.
Very easily done with Post build task plugin.
You can also run arbitrary commands using the Groovy Post Build - and that will give you a lot of control over when they run and so forth. We use that to run a 'finger of blame' shell script in the case of failed or unstable builds.
if (manager.build.result.isWorseThan(hudson.model.Result.SUCCESS)) {
item = hudson.model.Hudson.instance.getItem("PROJECTNAMEHERE")
lastStableBuild = item.getLastStableBuild()
lastStableDate = lastStableBuild.getTime()
formattedLastStableDate = lastStableDate.format("MM/dd/yyyy h:mm:ss a")
now = new Date()
formattedNow = now.format("MM/dd/yyyy h:mm:ss a")
command = ['/appframe/jenkins/appframework/fob.ksh', "${formattedLastStableDate}", "${formattedNow}"]
manager.listener.logger.println "FOB Command: ${command}"
manager.listener.logger.println command.execute().text
}
(Our command takes the last stable build date and the current time as parameters so it can go investigate who might have broken the build, but you could run whatever commands you like in a similar fashion)
If I'm reading your question right, you want to run a script in the post build actions part of the build.
I myself use PostBuildScript Plugin for running git clean -fxd after the build has archived artifacts and published test results. My Jenkins slaves have SSD disks, so I do not have the room keep generated files in the workspace.
You should be able to do that with the Batch Task plugin.
Create a batch task in the project.
Add a "Invoke batch tasks" post-build option selecting the same project.
An alternative can also be Post build task plugin.
You'd have to set up the post-build shell script as a separate Jenkins job and trigger it as a post-build step. It looks like you will need to use the Parameterized Trigger Plugin as the standard "Build other projects" option only works if your triggering build is successful.

How to run multiple tasks in Ruby?

I have a Capistrano deploy.rb script which has multiple tasks that can be invoked on the command line
cap site1_to_live deploy
cap site2_to_live deploy
(...etc)
I have tried combining these into a single task as follows
task :all_to_live do
site1_to_live
site2_to_live
site3_to_live
end
However, only one of the tasks is executed. How can I get all of them to run?
Define rake task which would group the subtasks. Run this single rake task with capistrano.
This is better because you will be also able to run this grouping task locally.

Resources