2017-01-30 8 views
2

Jimkins変数をパスワードデータベースとしてPomのプロファイルに設定する必要がありますが、${env.passwordb}(下図参照)を設定すると、プロジェクトはコンパイルされずにエラーが発生します。しかし私がJenkinsにコードをプッシュすると、変数を受け取り、プロジェクトを完全に実行します。私は何を変える必要がありますか?データベースパスワードをpom.xmlに設定する方法

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
      http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.company.vrs</groupId> 
    <artifactId>company-vrs</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.tomcat.maven</groupId> 
       <artifactId>tomcat7-maven-plugin</artifactId> 
       <version>2.2</version> 
       <configuration> 
        <url>${env.urlTomcat}</url> 
        <path>${env.appPath}</path> 
        <username>${env.username}</username> 
        <password>${env.password}</password> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <packaging>war</packaging> 
    <name>company-vrs</name> 
    <url>http://maven.apache.org</url> 
    <profiles> 
     <profile> 
      <id>dev</id> 
      <build> 
       <finalName>visitors</finalName> 
       <resources> 
        <resource> 
         <directory>src/main/resources</directory> 
         <filtering>true</filtering> 
         <excludes> 
          <exclude>**/*.jks</exclude> 
         </excludes> 
        </resource> 
        <resource> 
         <directory>src/main/resources</directory> 
         <filtering>false</filtering> 
         <includes> 
          <include>**/*.jks</include> 
         </includes> 
        </resource> 
       </resources> 
       <plugins> 
        <plugin> 
         <groupId>org.codehaus.mojo</groupId> 
         <artifactId>exec-maven-plugin</artifactId> 
         <version>1.3</version> 
         <configuration> 
          <mainClass>com.company.vrs.config.AppConfig</mainClass> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-war-plugin</artifactId> 
         <version>2.4</version> 
         <configuration> 
          <failOnMissingWebXml>false</failOnMissingWebXml> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.eclipse.jetty</groupId> 
         <artifactId>jetty-maven-plugin</artifactId> 
         <version>9.2.0.RC0</version> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.tomcat.maven</groupId>asta que 
         <artifactId>tomcat7-maven-plugin</artifactId> 
         <version>2.2</version> 
         <configuration> 
          <port>9090</port> 
          <path>/</path> 
         </configuration> 
        </plugin> 
       </plugins> 
      </build> 
      <properties> 
       <db.url>jdbc:postgresql://hsvvrsdev.company.com:5432/vrs_dev</db.url> 
       <db.username>vrsuser</db.username> 
       <db.password>${env.passworddb}</db.password> 
       <isdev>true</isdev> 
       <realm.metadata.file>/metadata/secureAuth_dev.xml</realm.metadata.file> 
       <realm.metadata.url>https://ssodev.company.com/SecureAuth68/metadata.xml</realm.metadata.url> 
       <realm.url.restart>https://ssodev.company.com/SecureAuth68/restart.aspx</realm.url.restart> 
      </properties> 
     </profile> 
     <profile> 
      <id>sqa</id> 
      <build> 
       <finalName>visitors_sqa</finalName> 
       <resources> 
        <resource> 
         <directory>src/main/resources</directory> 
         <filtering>true</filtering> 
         <excludes> 
          <exclude>**/*.jks</exclude> 
         </excludes> 
        </resource> 
        <resource> 
         <directory>src/main/resources</directory> 
         <filtering>false</filtering> 
         <includes> 
          <include>**/*.jks</include> 
         </includes> 
        </resource> 
       </resources> 
       <plugins> 
        <plugin> 
         <groupId>org.codehaus.mojo</groupId> 
         <artifactId>exec-maven-plugin</artifactId> 
         <version>1.3</version> 
         <configuration> 
          <mainClass>com.company.vrs.config.AppConfig</mainClass> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-war-plugin</artifactId> 
         <version>2.4</version> 
         <configuration> 
          <failOnMissingWebXml>false</failOnMissingWebXml> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.eclipse.jetty</groupId> 
         <artifactId>jetty-maven-plugin</artifactId> 
         <version>9.2.0.v20140526</version> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.tomcat.maven</groupId> 
         <artifactId>tomcat7-maven-plugin</artifactId> 
         <version>2.2</version> 
         <configuration> 
          <port>9090</port> 
          <path>/</path> 
         </configuration> 
        </plugin> 
       </plugins> 
      </build> 
      <properties> 
       <db.url>jdbc:postgresql://hsvvrsdev.company.com:5432/vrs_sqa</db.url> 
       <db.username>vrsuser</db.username> 
       <db.password>vrs#2015!</db.password> 
       <istest>true</istest> 
       <realm.metadata.file>/metadata/secureAuth_dev.xml</realm.metadata.file> 
       <realm.metadata.url>https://ssodev.company.com/SecureAuth68/metadata.xml</realm.metadata.url> 
       <realm.url.restart>https://ssodev.company.com/SecureAuth68/restart.aspx</realm.url.restart> 
      </properties> 
     </profile> 
     <profile> 
      <id>pro</id> 
      <build> 
       <finalName>visitors</finalName> 
       <resources> 
        <resource> 
         <directory>src/main/resources</directory> 
         <filtering>true</filtering> 
         <excludes> 
          <exclude>**/*.jks</exclude> 
         </excludes> 
        </resource> 
        <resource> 
         <directory>src/main/resources</directory> 
         <filtering>false</filtering> 
         <includes> 
          <include>**/*.jks</include> 
         </includes> 
        </resource> 
       </resources> 
       <plugins> 
        <plugin> 
         <groupId>org.codehaus.mojo</groupId> 
         <artifactId>exec-maven-plugin</artifactId> 
         <version>1.3</version> 
         <configuration> 
          <mainClass>com.company.vrs.config.AppConfig</mainClass> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-war-plugin</artifactId> 
         <version>2.4</version> 
         <configuration> 
          <failOnMissingWebXml>false</failOnMissingWebXml> 
         </configuration> 
        </plugin> 
        <plugin> 
         <groupId>org.eclipse.jetty</groupId> 
         <artifactId>jetty-maven-plugin</artifactId> 
         <version>9.2.0.v20140526</version> 
        </plugin> 
        <plugin> 
         <groupId>org.apache.tomcat.maven</groupId> 
         <artifactId>tomcat7-maven-plugin</artifactId> 
         <version>2.2</version> 
         <configuration> 
          <port>9090</port> 
          <path>/</path> 
         </configuration> 
        </plugin> 
       </plugins> 
      </build> 
      <properties> 
       <db.url>jdbc:postgresql://hsvvrsdb.company.com:5432/vrs</db.url> 
       <db.username>vrsuser</db.username> 
       <db.password>v14r3s20150302</db.password> 
       <ispro>true</ispro> 
       <realm.metadata.file>/metadata/secureAuth_prod.xml</realm.metadata.file> 
       <realm.metadata.url>https://sso.company.com/visitors/metadata.xml</realm.metadata.url> 
       <realm.url.restart>https://sso.company.com/visitors/restart.aspx</realm.url.restart> 
      </properties> 
     </profile> 
    </profiles> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <spring-version>4.1.2.RELEASE</spring-version> 
     <spring-data-jpa-version>1.6.1.RELEASE</spring-data-jpa-version> 
     <spring-data-commons-version>1.8.1.RELEASE</spring-data-commons-version> 
     <hibernate-version>4.3.5.Final</hibernate-version> 
     <org-slf4j-version>1.7.7</org-slf4j-version> 
     <spring-ldap-version>2.0.1.RELEASE</spring-ldap-version> 
     <spring-security-version>3.2.3.RELEASE</spring-security-version> 
     <bonecp-version>0.8.0.RELEASE</bonecp-version> 
     <maven.compiler.source>1.8</maven.compiler.source> 
     <maven.compiler.target>1.8</maven.compiler.target> 
    </properties> 
    <dependencies> 
      ..... many dependencies ....   
    </dependencies> 
</project> 

エラー:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'env.passworddb' in string value "${env.passworddb}"

+0

私はそのポンポンでenv.passwordb変数を参照してくださいいけない..私はsmoething行方不明ですか? –

+0

@MaciejKowalski申し訳ありませんが、私は別の名前を持っていました。 $ {env.passworddb}に変更されました。 –

+0

ビルドをローカルでどのように実行しますか? –

答えて

3

調査のビットの後には、$ {env.passwddbは}のみ、リモート・ジェンキンス環境に存在していたことが判明しました。それを克服し、今でも同じプロファイルconnfigurationを使用するには、可能な解決策は次のようになります。ローカル環境で

1)打ち

パスワードは、プロパティファイル内にハードコードされるべきです。 1つはリモート、プレースホルダはまだ存在します。 Mavenのコマンドラインを通過した

2)パスワード:

mvn clean package resources:testResources -Denv.passwddb=realpass 
+1

1)は、特にハードコードされた値がリポジトリ内で終わる可能性がある場合、危険な解決策のように聞こえます。 '.m2/settings.xml'ファイルの中でMavenプロファイルを使って変数を設定しようとすることもできます。 –

関連する問題