Add WORKSPACE environment variable for Build jobs

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Add WORKSPACE environment variable for Build jobs

Folke Lemaitre-3
Hi,

A simple but very useful addition to the environment variables present for the build scripts, would be the workspace.
Since I cannot commit this on cvs, it would be nice if someone else could.

Index: src/main/java/hudson/model/AbstractBuild.java
===================================================================
RCS file: /cvs/hudson/hudson/main/core/src/main/java/hudson/model/AbstractBuild.java,v
retrieving revision 1.24
diff -u -r1.24 AbstractBuild.java
--- src/main/java/hudson/model/AbstractBuild.java    21 Apr 2007 14:10:25 -0000    1.24
+++ src/main/java/hudson/model/AbstractBuild.java    2 May 2007 15:37:09 -0000
@@ -215,6 +215,7 @@
     @Override
     public Map<String,String> getEnvVars() {
         Map<String,String> env = super.getEnvVars();
+        env.put("WORKSPACE", getProject().getWorkspace().getRemote());
 
         JDK jdk = project.getJDK();
         if(jdk !=null)

Best Regards,
Folke
Reply | Threaded
Open this post in threaded view
|

Re: Add WORKSPACE environment variable for Build jobs

Jesse Glick
Folke Lemaitre wrote:
> A simple but very useful addition to the environment variables
> present for the build scripts, would be the workspace.

For a shell script, you could just define it yourself:

WORKSPACE=`pwd`

For Ant, you could use ${user.dir}.

Am I missing something? Or do you just want a clearer variable name as a
convenience?

-J.

--
[hidden email]  netbeans.org  ant.apache.org  hudson.dev.java.net
             http://google.com/search?q=e%5E%28pi*i%29%2B1

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Add WORKSPACE environment variable for Build jobs

Folke Lemaitre-3
Actually, the current directory is not the same as the workspace directory if you use a SCM. If you have multiple scm modules configured for a certain hudson project, then the current directory will always be the directory of the first SCM module, which is kinda strange, but might be convenient for simple projects. It also gives issues when sharing ant scripts in several hudson projects, where it might be the case that those ant scripts don't always reside in the same workspace folder.

I could probably change my ant scripts so that they set WORKSAPCE={user.dir}/.., but I still believe the simple addition of a WORKSPACE environment variable would be useful.

Best Regards,
Folke

On 5/2/07, Jesse Glick <[hidden email]> wrote:
Folke Lemaitre wrote:
> A simple but very useful addition to the environment variables
> present for the build scripts, would be the workspace.

For a shell script, you could just define it yourself:

WORKSPACE=`pwd`

For Ant, you could use ${user.dir}.

Am I missing something? Or do you just want a clearer variable name as a
convenience?

-J.

--
[hidden email]  netbeans.org  ant.apache.org  hudson.dev.java.net
             http://google.com/search?q=e%5E%28pi*i%29%2B1

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]




--
Adres: Nieuwevaart 232, 9000 Gent, Belgium
Phone: +32486291702
Photos: http://picasaweb.google.com/folke.lemaitre
Music: http://www.last.fm/user/flemaitr/
Digg: http://digg.com/users/Zypher
Reply | Threaded
Open this post in threaded view
|

Re: Add WORKSPACE environment variable for Build jobs

Jesse Glick
Folke Lemaitre wrote:
> Actually, the current directory is not the same as the workspace
> directory if you use a SCM. If you have multiple scm modules
> configured for a certain hudson project, then the current directory
> will always be the directory of the first SCM module, which is kinda
> strange, but might be convenient for simple projects.

If you mean that you use CVS and specify several modules, then just
check Legacy Mode. Most of my projects work this way and the workspace,
i.e. the dir containing all the modules, is the current dir as expected.
I've never tried leaving the (poorly named) Legacy Mode unchecked so I
don't know what its behavior is.

-J.

--
[hidden email]  netbeans.org  ant.apache.org  hudson.dev.java.net
             http://google.com/search?q=e%5E%28pi*i%29%2B1

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Add WORKSPACE environment variable for Build jobs

Folke Lemaitre-3
Actually I'm using subversion and as far as I can see, there is no legacy mode there...

On 5/4/07, Jesse Glick <[hidden email]> wrote:
Folke Lemaitre wrote:
> Actually, the current directory is not the same as the workspace
> directory if you use a SCM. If you have multiple scm modules
> configured for a certain hudson project, then the current directory
> will always be the directory of the first SCM module, which is kinda
> strange, but might be convenient for simple projects.

If you mean that you use CVS and specify several modules, then just
check Legacy Mode. Most of my projects work this way and the workspace,
i.e. the dir containing all the modules, is the current dir as expected.
I've never tried leaving the (poorly named) Legacy Mode unchecked so I
don't know what its behavior is.

-J.

--
[hidden email]   netbeans.org  ant.apache.org  hudson.dev.java.net
             http://google.com/search?q=e%5E%28pi*i%29%2B1

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]




--
Adres: Nieuwevaart 232, 9000 Gent, Belgium
Phone: +32486291702
Photos: http://picasaweb.google.com/folke.lemaitre
Music: http://www.last.fm/user/flemaitr/
Digg: http://digg.com/users/Zypher
Reply | Threaded
Open this post in threaded view
|

Re: Add WORKSPACE environment variable for Build jobs

Kohsuke Kawaguchi
Administrator
In reply to this post by Folke Lemaitre-3
Adding an environment variable is fairly low-cost, and you've even
kindly provided a patch, so I'm happy to do it.

(But I agree with Jesse that it's probably not that difficult to
compute that either.)

2007/5/3, Folke Lemaitre <[hidden email]>:

> Actually, the current directory is not the same as the workspace directory
> if you use a SCM. If you have multiple scm modules configured for a certain
> hudson project, then the current directory will always be the directory of
> the first SCM module, which is kinda strange, but might be convenient for
> simple projects. It also gives issues when sharing ant scripts in several
> hudson projects, where it might be the case that those ant scripts don't
> always reside in the same workspace folder.
>
> I could probably change my ant scripts so that they set
> WORKSAPCE={user.dir}/.., but I still believe the simple addition of a
> WORKSPACE environment variable would be useful.
>
> Best Regards,
> Folke
>
>
>  On 5/2/07, Jesse Glick <[hidden email]> wrote:
> > Folke Lemaitre wrote:
> > > A simple but very useful addition to the environment variables
> > > present for the build scripts, would be the workspace.
> >
> > For a shell script, you could just define it yourself:
> >
> > WORKSPACE=`pwd`
> >
> > For Ant, you could use ${user.dir}.
> >
> > Am I missing something? Or do you just want a clearer variable name as a
> > convenience?
> >
> > -J.
> >
> > --
> > [hidden email]   netbeans.org  ant.apache.org  hudson.dev.java.net
> >
> http://google.com/search?q=e%5E%28pi*i%29%2B1
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
>
> --
> Adres: Nieuwevaart 232, 9000 Gent, Belgium
> Phone: +32486291702
> Photos: http://picasaweb.google.com/folke.lemaitre
> Music: http://www.last.fm/user/flemaitr/
> Digg: http://digg.com/users/Zypher


--
Kohsuke Kawaguchi

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]