开发者

Jenkins does not filter Maven resources with environment variables on free-style projects

开发者 https://www.devze.com 2023-04-05 21:06 出处:网络
It seems that Jenkins manages differently the environment variables when the job is a Maven 2/3 project or if it is a free-style project.

It seems that Jenkins manages differently the environment variables when the job is a Maven 2/3 project or if it is a free-style project.

Let me show you my tests.

The project

It's a simple Java 1.6 project (generated for example by the default Maven archetype), which contains, in src/main/resources, the following myfile.xml:

<foo>
    <bar>${project.version}</bar>
    <bar>${foo.bar}</bar>
</foo>

In my pom.xml, I ask Maven to filter this directory:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

Now, I define the foo.bar property as a Windows environment (equals to 42).

In the System Information in the Jenkins administration page, I see this variable in the Environment Variables section.

Test 1

I create a new "maven 2/3 project" in Jenkins, and set the basics configuration: Java and Maven versions, the Maven goals (clean package). I run this job, and finally, I get the following myfile.xml:

<foo>
    <bar>1.0-SNAPSHOT</bar>
    <bar>42</bar>
</foo>

In this case, both variables were filtered by Maven.

Test 2

I create a new "free-style software project" in Jenkins, and set the same configuration as in Test 1, by adding one build step, a top level Maven target. The same Maven command is used, i.e. clean package. Once the build is done, the myfile.xml looks like:

<foo>
    <bar>1.0-SNAPSHOT</bar>
    <bar>${foo.bar}</bar>
</foo>

So apparently, the environment variable foo.bar is not considered when the build is based on a free-sty开发者_如何学Cle project.

My question: is there any reason to have such a behavior? Or is it a Jenkins bug?


Jenkins v1.430 (installed on a Windows 2003 server), Maven 2.0.9 or Maven 2.2.1 (same behavior), Java 1.6


I'm experiencing the same thing.

My workaround was to go to the project's configure page, click on "Advanced" for the Maven build step, and define my properties in the provided textfield like foo.bar=42


I think this because of a bug in Maven and not a Jenkins issue.

I faced the same problem (irrespective of Jenkins job configuration) when using Maven 3.0.3. After upgrading to Maven 3.0.4 the problem was resolved.

0

精彩评论

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