开发者

How can I pass Hudson's env.EXECUTOR_NUMBER to log4j properties and Java's System.getProperty

开发者 https://www.devze.com 2023-03-27 01:45 出处:网络
My Hudson job calls a single XML database collection and a single log file. E.g. /db/project ${user.home}/logs/logging.log

My Hudson job calls a single XML database collection and a single log file. E.g.

  • /db/project
  • ${user.home}/logs/logging.log

I'd like to inject Hudson's env.EXECUTOR_NUMBER in both paths to avoid concurrent execution clashes. E.g.

  • /db/project {$EXECUTOR_NUMBER}
  • {$user.home}/logs {$EXECUTOR_NUMBER}/logging.log

I've found out the following:

  • Hudson site states that I need to pass Hudson's EXECUTOR_NUMBER to Maven as part of the build goal.
  • Log4J can only use system variables not environment variables (as these are a platform specific concept)

Now that I've got Hudson's EXECUTOR_NUMBER variable specified in the build goal, how can I use this as开发者_如何转开发 a system property for use by Log4J and Java's System.getProperties() class?


You can pass System Properties to any Java process using the -D syntax.

mvn clean install -DEXECUTOR_NUMBER={$EXECUTOR_NUMBER}

For a test class in a forked run, you will additionally have to configure the surefire plugin to pass the system property to the forked vm:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.9</version>
    <configuration>
      <systemPropertyVariables>
        <EXECUTOR_NUMBER>${EXECUTOR_NUMBER}</EXECUTOR_NUMBER>
      </systemPropertyVariables>
    </configuration>
  </plugin>
0

精彩评论

暂无评论...
验证码 换一张
取 消