Gradle multiple tasks,each running commandline on Jenkins

(Shanthi Natarajan) #1

Dear All,
My requirement is to generate mutiple message broker bar files for my build. I use gradle and run this on Jenkins installed on Windows. I use the following piece of code for generating the bar files and later I use the configuration to upload the files to artifactory,

project_list.each{ projName ->
task “createBar$projName”() {
println “Hello I am trying to create a bar file + ${WORKING_BASE_DIR}” +"${projName}"
def cmd="mqsicreatebar -data ${WORKING_BASE_DIR} -b ${WORKING_BASE_DIR}/bar/${projName}-${VERSION}.bar -cleanBuild -a ${projName}"
def workingDir = “${WORKING_BASE_DIR}”+"build_scripts"
def process = cmd.execute(null, new File(workingDir))
process.consumeProcessOutput(System.out, System.err)
if (process.exitValue() != 0)
throw new Exception("Command failed. Error code " + process.exitValue() + “. " + cmd);
fileName =”${WORKING_BASE_DIR}/bar/${projName}-${VERSION}.bar"
println "File to be uploaded actual … "+fileName
destFile = file(new File(fileName))
println “File path :”+ destFile.path
allJars destFile
createAllBars.dependsOn “createBar$projName”

Please can you help me find out what I am doing wrong here … since this just hangs for sometime and never generates the bar files. I can see the task manager spawns new mqsicreatebar process.I am new to gradle and still learning.

(Stefan Oehme) #2

You are running your bar creation during the configuration phase. The action of a task needs to be specified in a doLast {} block.

task "createBar"() {
  //configuration of inputs and outputs goes here
  //without input/output declaration, up-to-date checking won't work
  doLast {
    //execution goes here

(Shanthi Natarajan) #3

Thanks Stefan for the response. I found my message broker workspace corrupted as well. Now I am able to generate the bars correctly.