0

I am trying to run a ear task with ant on Jenkins. The ant task builds successfully on my local machine.

However, when I try to build using Jenkins, I get the following error: "specified workspace is not valid". I tried hardcoding the workspace value, I tried getting it from the environment variables and I also tried to define it in a custom workspace and then accessing it.

But I keep getting the following error:

[subProjEAR] $ cmd.exe /C '"F:\Build\Ant\apache-ant-1.8.4\bin\ant.bat && exit       %%ERRORLEVEL%%"'
 Buildfile: E:\Jenkins\jobs\ProjectDev\workspace\subProjEAR\build.xml

init.env:

init.typedefs:
Trying to override old definition of task apt

init:

BUILD FAILED

E:\Jenkins\jobs\ProjDev\workspace\subProjEAR\build.xml:81: Specified workspace directory "E:\Jenkins\jobs\ProjDev\workspace" is not valid.

Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure`

The code snipped around line 81 is as below

    <target name="init" depends="init.env,init.typedefs" unless="init.executed">
    <property name="init.executed" value="true" />
    <fail unless="workspace" message="The workspace property needs to be set!" />
    <dirname property="project.dir" file="${ant.file}" />
    <property name="echo.metadata" value="false" />

    <!-- Line below is no 81 -->
    <mdimport workspace="${workspace}" pjdir="${project.dir}" echo="${echo.metadata}"> 


    </mdimport>
    <property name="archive.name" value="${project.name}.ear"/>
    <property name="uri" value=""/>
    </target>

I have created an environment variable named as WORKSPACE in my "local machine". Echoing prints it correctly ( C:\bea\user_projects\w4WP_workspaces\myProjWS). I have also set the WORKSPACE environment variable on the Jenkins machine. This is the same workspace as Jenkins. Echo on Jenkins prints the below:

Buildfile: E:\Jenkins\jobs\ProjectDev\workspace\subProjEAR\build.xml

init.env:

init.typedefs:
Trying to override old definition of task apt

init:
     [echo] workspace : E:\Jenkins\jobs\ProjectDev\workspace 
     [echo] weblogic workspace : ${env.WORKSHOP_WORKSPACE}


BUILD FAILED
E:\Jenkins\jobs\ProjectDev\workspace\subProjEAR\build.xml:85: Specified workspace directory "E:\Jenkins\jobs\ProjectDev\workspace" is not valid.

Please help.

Priyanka
  • 1
  • 1
  • 2
  • Try making Jenkins the owner of the workspace and files inside of it if Jenkins is not the current owner. If you created the workspace manually, you should move the files out of it, run Jenkins, and Jenkins will have created its own workspace for the job. – elrobe Aug 21 '14 at 12:42
  • Thanks elrobe for reply. Workspace is created by Jenkins only. Before building, Jenkins is checking out all the project files from cvs into the workspace and then after checkout completes, it builds it and thats when the error arises. – Priyanka Aug 21 '14 at 12:55

1 Answers1

0

Best way to access WORKSPACE from ANT is through:

<property environment="env" />
<echo message="${env.WORKSPACE}" />

It doesn't seem like a Jenkins error, as Jenkins is able to successfully load the build file from that workspace. What is on line: 81 of that build.xml? The cause of the problem is there. Paste a snippet of your build file around line: 81

Edit after author comments
So, as I guessed, it wasn't anything to do with Jenkins. The issue is with <mdimport> task. So far, I've been able to find zero documentation about it, other that it comes from Weblogic

It is this task that is throwing the error. And considering that Weblogic and Jenkins have little to do with each other, I doubt you should be passing Jenkins's workspace for this task. It is probably looking for some Weblogic workspace.

Do you have a Weblogic workspace checked out under a subfolder in Jenkins, like my_checkout_folder? If so, maybe you should use ${workspace}/my_checkout_folder for that task?

In this issue from someone, they are reading ${workspace}/workspace.xml file

In this example (which looks very similar to yours), the value of workspace comes from environment variable WORKSHOP_WORKSPACE. Do you have that environment variable set on your local machine (the one where it works)?

Probable cause

It just came to me, while reviewing your question.

  • You said it works on local machine, but not on Jenkins.
  • If you are using the same ant file on both, means you are expecting an environment variable workspace to be present on your local machine, right? (Otherwise the same ant script wouldn't have worked on local)
  • Jenkins, when executing a build, has its own environment variable workspace which has nothing to do with the one you might be having on your local machine. Jenkins's workspace variable defines its job's working directory.
  • Even if you manually set a global workspace environment variable on Jenkins machine, it will be overwritten by the job's workspace everytime it runs.

Do the following test:

  • echo workspace environment variable on your local machine
  • in Jenkins job, use "execute shell" (or "execute windows batch command") to echo workspace from within the job.

Paste the result here. But you can also compare them yourself.

Community
  • 1
  • 1
Slav
  • 27,057
  • 11
  • 80
  • 104
  • Yeah, currently I am using workspace like that only. – Priyanka Aug 22 '14 at 06:09
  • Thanks @Slav for response. I have modified my questions by adding the echoed values of workspace. Jenkins prints the correct value of workspace, but the error still persists. – Priyanka Sep 01 '14 at 05:45
  • I can't say much more other than that the `mdimport` task seems to expect a different value of `WORKSPACE` than what Jenkins has. I am not sure where `mdimport` task comes from... Weblogic? I suggest you make a support ticket with Weblogic and ask them what value it expects – Slav Sep 01 '14 at 13:22