views:

331

answers:

3

I want to create a hudson job, that takes an id as a parameter. And use that id to calculate the svn-repo path.

Where I work you have a svn path for every issue that you resolve. And then all the issues are joined into a single svn-path.

What I want to do is to run static code analysis on the partial issues.

So I think maybe having an Ant build.xml that I use for every issue, then, parametrize the job with the issue id.

I have tried to achieve that but the svn path doesn't replace the parameter.

I have tried with #issueId, %issueId%, ${issueId} and ${env.issueId} without success.

Jump error like:

Location 'http://svn-path:8181/svn/devSet/issues/${env.chuid}' does not exist
Checking out a fresh workspace because C:\Documents and Settings\dnoseda\.hudson\jobs\test\workspace\${env.chuid} doesn't exist
Checking out http://svn-path:8181/svn/devSet/issues/${env.chuid}
ERROR: Failed to check out http://svn-path:8181/svn/devSet/issues/${env.chuid}
org.tmatesoft.svn.core.SVNException: svn: '/svn/!svn/bc/46190/devSet/issues/$%7Benv.chuid%7D' path not found: 404 Not Found (http://svn-path:8181)
    at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:64)
    at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:51)
    at 

I am think that I can not do what I want.

Do you know how I can setup the correct configuration to achieve this matter?

Thanks for any help.

Edit The section of the configurate job that I want to put this parameter is this:

<scm class="hudson.scm.SubversionSCM">
<locations>
      <hudson.scm.SubversionSCM_-ModuleLocation>
        <remote>http://svn-path:8181/svn/devSet/issues/${env.issueid}&lt;/remote&gt;
      </hudson.scm.SubversionSCM_-ModuleLocation>
    </locations>

New Edit: Solved

My version of hudson it was the last (1.349), but the version of svn plugin it was 1.11, being the last the 1.13, and it work with ${issueId}

Thank for the anwsers

+3  A: 

From the hudson wiki:

"The parameter are available as environment parameters. So e.g. a shell ($FOO, %FOO%) or Ant ( ${env.FOO} ) can access these values."

Your syntax doesn't match the one in the wiki.

Tomislav Nakic-Alfirevic
You are right. I have tried that to. I had just modified the question with the correct info.
damian
Hudson converts your variable name to upper case and you are using shell(I'm assuming) so you want to use `http://svn-path:8181/svn/devSet/issues/$ISSUEID`
prestomation
You can put an `env` right in your build script to print out the current environment to confirm the parameter is making it that far
prestomation
I am not using shell, only configurate the configurate the origin of source section when you configurate a job. In the field Repository URL
damian
with ...$ISSUEID doesn't work eigther
damian
Oh sorry, thought you were using it straight in the build script. Try `${ISSUEID}`
prestomation
Nop, doesn't work, I had the same error.
damian
If the SVN plugin is anything like the one for Git, I don't think this can be done (though I'd be happy to be wrong in both cases).
Christopher
I configured a job that takes a tag as a parameter and checks out my code. The URL looks like: http://subversion/svn/.../tags/${SVN_TAG} Be sure to define the parameter as upper case as well. I also unchecked the use update option for the SCM.
Peter Schuetze
+2  A: 

In this comment, it is mentioned that they use the ${ISSUEID}, which is why I suggested it, but all other signs I see say this doesn't actually work.

Otherwise I would recommend not using the SCM plugin and doing the SVN operation in a build script step. This would allow you to use the parameters as env variables like $ISSUEID

prestomation
I see. But, can you configure hudson to poll the SCM for updates from the build script step ?
damian
Assuming you are on Unix:It's just a shell script. Turn off the SCM plugin and put your commands right in a build step. Exactly like you'd type it on your machine to do it manually`svn co http://path/to/my/repo/$ISSUEID``make`or whatever
prestomation
That seems to work. So how do I configure the job, by scripting, to check if there is a change in te SCM, and only if there is, to execute the job?With the SCM plugin you can do that, and it's the only reason that I tried to use it.
damian
I'm not familiar with SVN, but you'd have to script it. Grep the output of your svn command to determine to continue or not.
prestomation
+3  A: 

I've setup a svn project that does the parameter substitution successfully. The syntax is indeed ${issueId} so I assume you are doing something wrong, or are using a very old version of Hudson. Could you update the question with the versions of Hudson and the subversion plugin that you are using?

<project> 
  <actions/> 
  <description></description> 
  <keepDependencies>false</keepDependencies> 
  <properties> 
    <hudson.model.ParametersDefinitionProperty> 
      <parameterDefinitions> 
        <hudson.model.StringParameterDefinition> 
          <name>issueId</name> 
          <description></description> 
          <defaultValue>none</defaultValue> 
        </hudson.model.StringParameterDefinition> 
      </parameterDefinitions> 
    </hudson.model.ParametersDefinitionProperty> 
  </properties> 
  <scm class="hudson.scm.SubversionSCM"> 
    <locations> 
      <hudson.scm.SubversionSCM_-ModuleLocation> 
        <remote>https://svn.dev.java.net/svn/hudson/trunk/${issueId}&lt;/remote&gt; 
      </hudson.scm.SubversionSCM_-ModuleLocation> 
    </locations> 
    <useUpdate>true</useUpdate> 
    <excludedRegions></excludedRegions> 
    <excludedUsers></excludedUsers> 
    <excludedRevprop></excludedRevprop> 
  </scm> 
  <canRoam>true</canRoam> 
  <disabled>false</disabled> 
  <triggers class="vector"/> 
  <concurrentBuild>false</concurrentBuild> 
  <builders/> 
  <publishers/> 
  <buildWrappers/> 
</project>

Here is the build output. The checkout fails due to an authentication issue, but the parameter is successfully replaced:

Started by user anonymous
Building on master
Checking out a fresh workspace because C:\hudson\jobs\test-svn\workspace\${issueId} doesn't exist
Checking out https://svn.dev.java.net/svn/hudson/trunk/www
ERROR: Failed to check out https://svn.dev.java.net/svn/hudson/trunk/www
org.tmatesoft.svn.core.SVNCancelException: svn: No credential to try. Authentication failed
    at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.cancel(SVNErrorManager.java:37)
    at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.cancel(SVNErrorManager.java:32)
    at org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager.getFirstAuthentication(DefaultSVNAuthenticationManager.java:168)
    at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:534)
    at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:273)
    at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:261)
    at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.exchangeCapabilities(DAVConnection.java:516)
    at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.open(DAVConnection.java:98)
    at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.openConnection(DAVRepository.java:1001)
    at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.getLatestRevision(DAVRepository.java:178)
    at org.tmatesoft.svn.core.wc.SVNBasicClient.getRevisionNumber(SVNBasicClient.java:482)
    at org.tmatesoft.svn.core.wc.SVNBasicClient.getLocations(SVNBasicClient.java:851)
    at org.tmatesoft.svn.core.wc.SVNBasicClient.createRepository(SVNBasicClient.java:534)
    at org.tmatesoft.svn.core.wc.SVNUpdateClient.doCheckout(SVNUpdateClient.java:893)
    at org.tmatesoft.svn.core.wc.SVNUpdateClient.doCheckout(SVNUpdateClient.java:791)
    at hudson.scm.SubversionSCM$CheckOutTask.invoke(SubversionSCM.java:615)
    at hudson.scm.SubversionSCM$CheckOutTask.invoke(SubversionSCM.java:541)
    at hudson.FilePath.act(FilePath.java:676)
    at hudson.FilePath.act(FilePath.java:660)
    at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:534)
    at hudson.scm.SubversionSCM.checkout(SubversionSCM.java:482)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:898)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:400)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:349)
    at hudson.model.Run.run(Run.java:1106)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:93)
    at hudson.model.Executor.run(Executor.java:122)
Notifying upstream projects of job completion
Finished: FAILURE
Michael Donohue