2012-09-21 4 views
3

저는 Jenkins에 익숙하지만 Maven에 익숙하지 않습니다. 젠킨스에서 Maven 작업을 수행하여 ApplicationContext.xml 파일의 환경 변수를 확장하는 방법을 파악하려고합니다.Maven 확장을 중지하는 방법 env. 젠킨스가있는 변수?

<!-- 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> 

문제는 WEB-INF/ApplicationContext.xml를 구축, 메이븐에서 젠킨스에 의해 실행 빌드 것입니다 : 우리 ApplicationContext.xml 파일 내부

우리는 (우리가 만든) Tomcat이 부하/실행 시간을 확장 이는 ${DeployMode} 환경 변수를 참조 빌드 시스템에서 설정 한 환경 변수가 있다면 다음과 같습니다 (의 말을하자이 예에서는 '생산성'에) :

<!-- 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> 

그래서 값이 이제 WAR에 "하드 코딩"된 것이며, 항상 행동 할 것이다 like "Pro d "대상 웹 서버의 환경 변수가 'Staging'과 같은 다른 값으로 설정된 DeployMode 인 경우에도 마찬가지입니다.

동일한 빌드 서버에서 Maven을 수동으로 실행하면 발생하지 않습니다. Jenkins가 작업을 빌드 할 때만 발생합니다.

Jenkins에게이 동작을 중지시킬 수있는 설정이 있습니까?

EnvInject 플러그인과 같은 옵션을 보았습니다. UNSET 작업이 실행될 때 모든 환경 변수가 실행되지만 실제로이 동작에 의아해하며 그 아래로 들어가고 싶습니다.

감사합니다. 업데이트 1

나는 최상위 POM에서 다음과 같은 자원 필터링 블록을 발견하고 우리의 AppContext.xml 파일을 건너 뛰도록 <excludes/> 블록을 추가 :

<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가 실행할 때 속성 목록에 추가되고 명령 줄에서 실행하면 무시됩니다. 내가 전에 몇 년에서이 허드슨의 문제를 발견했다하더라도 : 받는다는가 ls 명령을 찾을 수 있기 때문에

Resource filtering fails when run from Hudson는 EnvInjectPlugin는하지만, 적어도 PATH var에 제거에 광고하는 것을 수행, 빌드가 끊었다.

업데이트 2

Invoke top-level Maven targets 빌드 단계는 POM을 수정할 필요없이 원하는 결과를 생산하는 "프리 스타일 소프트웨어 프로젝트"에 "메이븐 2/3 프로젝트"에서 젠킨스의 작업을 변경하고 사용.

답변

2

젠킨스는 리소스 필터링을 어떻게 든 가능하게 할 수 있습니다. 필터링을 구성하기위한 선택의 폭이 넓습니다. 특정 확장자를 가진 파일로 필터링을 제한하거나, 필터에 빌드 속성을 포함하지 않도록 지시하거나, 다른 구분 기호를 완전히 필터링하도록 선택할 수 있습니다. resources:resources docs 또는 description of resource filtering concepts을 참조하십시오.

+0

답변 해 주셔서 감사합니다. 리소스 필터링 문제였습니다. 위의 업데이트를 참조하십시오. –

관련 문제