2

I want to copy files in ".jenkins" or in "Temp" direcotry.

<artifactId>maven-resources-plugin</artifactId>
    <version>2.7</version>
    <executions>        
      <execution>
        <id>copy-resource-one</id>
        <phase>install</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>C:\Users\user\.jenkins</outputDirectory>
                    <resources>
                        <resource>
                            <directory>${basedir}/src/main/resources</directory>
                            <includes>
                                <include>htmlTemplate.html</include>
                                <include>Chart.js</include>
                            </includes>
                        </resource>
                    </resources>
          </configuration>                        
      </execution>
    </executions>

This is how my pom.xml looks like for now. It is working for me on my local machine, but it won't work for another user.

This is what I want:

<outputDirectory> relative path to Temp </outPutDirectory>

Question: How can I ensure that the file is always copied in "temp" or in ".jenkins" folder? Is there any variable for that?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
Lino556
  • 133
  • 1
  • 9
  • Please post code inline; not images to it – fge Mar 07 '16 at 10:43
  • you hardcoded a path, that's definitely not the best practice and potentially what makes it not working on other machines – A_Di-Matteo Mar 07 '16 at 10:45
  • I know it's hardcoded. I want to get a relative path to "temp" and I don't know how. Please Help! – Lino556 Mar 07 '16 at 10:49
  • Stop using hard-coded path. You'll feel better. That'll probably solve your problem also, whatever it is. – Tunaki Mar 07 '16 at 10:52
  • I have no idea how a realtive path have to look like for "temp" foler. It's like I said. I know its hardcoded and I know a relative path would solve my problem, but how does a relative path look like in pom.xml? Please Help – Lino556 Mar 07 '16 at 10:54

3 Answers3

4

In Maven you can use Java properties as Maven properties for a build.

Maven exposes all properties from java.lang.System. Anything you can retrieve from System.getProperty() you can reference in a Maven property

So, in your case you could have the following:

<outputDirectory>${java.io.tmpdir}</outputDirectory>

And the output directory will point to the user temporary directory based on the host OS. For instance, in Windows 7 it would be

C:\Users\<user_Id>\AppData\Local\Temp

For a full list of Java properties, check official documentation, from which:

java.io.tmpdir: Default temp file path

You may also be interested in the user.home

user.home: User's home directory

So you probably wanted to point to ${user.home}\.jenkins.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
3

As said in the above comments, using hardcoded path is a really bad solution.

One solution should be to create a .jenkins folder in the /target folder:

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration>
        <tasks>
          <mkdir dir="${project.build.directory}/.jenkins"/>
        </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

And to use this .jenkins folder as an output folder:

<configuration>
   <outputDirectory>${project.build.directory}/.jenkins</outputDirectory>
   ...
</configuration>

It will work on all the build machines (developer laptop or server).

Bruno Lavit
  • 10,184
  • 2
  • 32
  • 38
2

In addition to suggested answers, you can also use HOMEPATH system variable, which is by default set on Windows systems.

   <outputDirectory>${HOMEPATH}/.jenkins</outputDirectory>

HOMEPATH resolves to \Users{username}

gmode
  • 3,601
  • 4
  • 31
  • 39