我對Jenkins很熟悉,但是對Maven來說是新的,我試圖找出如何通過擴展ApplicationContext.xml
文件中的環境變量來阻止Jenkins中的Maven作業。如何阻止Maven擴展env。變量瓦特/詹金斯?
裏面我們ApplicationContext.xml
文件,我們引用${DeployMode}
環境變量(我們創建)是Tomcat在加載擴展/運行時間:
<!-- SPRING CONTEXT static accessor -->
<beans:bean id="contextApplicationContextProvider"
class="com.dartneuroscience.compserv.rest.appcontext.AppContextProvider">
<beans:constructor-arg>
<beans:value>${DeployMode}</beans:value>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="location"
value="/WEB-INF/App_${DeployMode}.properties" />
</beans:bean>
的問題是,在一個Maven構建詹金斯運行,內置WEB-INF/ApplicationContext.xml
看起來是這樣的,如果有一個環境變量在構建機上設置(假設在這個例子中「PROD」):
<!-- SPRING CONTEXT static accessor -->
<beans:bean id="contextApplicationContextProvider"
class="com.dartneuroscience.compserv.rest.appcontext.AppContextProvider">
<beans:constructor-arg>
<beans:value>Prod</beans:value> <!-- Expanded env. var -->
</beans:constructor-arg>
</beans:bean>
<beans:bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="location"
value="/WEB-INF/App_Prod.properties" /> <!-- Expanded env. var -->
</beans:bean>
所以值現在是「硬編碼」到了戰爭,總是會採取行動像「Pro d「,即使目標Web服務器的環境變量DeployMode
設置爲其他值,如」暫存「。
當我在同一個構建服務器上手動運行Maven時,不會發生這種情況 - 它只發生在Jenkins構建作業時。
有沒有可以傳給Jenkins的設置來阻止這種行爲?
我已經看過EnvInject Plugin等所有環境變量作爲工作運行的選項,但我真的很困惑這種行爲,並想深究其底。
謝謝。
更新1
我發現在頂層POM以下資源過濾塊,並添加了<excludes/>
塊跳過我們AppContext.xml
文件:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<webResource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<includes>
<include>*.xml</include>
</includes>
<excludes>
<exclude>*AppContext.xml</exclude>
</excludes>
<targetPath>WEB-INF</targetPath>
<filtering>true</filtering>
</webResource>
</webResources>
但是,這仍然沒有回答爲什麼環境變量在由Jenkins運行時被添加到屬性列表中,並且在從命令行運行時被忽略;雖然我沒有從之前幾年發現這個問題哈德森:Resource filtering fails when run from Hudson
此外,EnvInjectPlugin做什麼它做廣告,但在除去至少PATH VAR,構建打破了,因爲行家找不到ls
命令。
更新2
改變詹金斯從「Maven的2/3工程」,「自由風格的軟件項目」的工作,並使用Invoke top-level Maven targets
生成步驟生成所需的結果,而無需修改POM。
非常感謝您的回答。這是資源過濾問題,請參閱我上面的更新。 –