簡體   English   中英

為 Ant SCP 任務存儲用戶名/密碼的最佳方法是什么

[英]what's the best way to store username/password for Ant SCP task

我需要使用 scp 任務來傳輸包含許多子文件夾和文件的整個文件夾。 目前我使用以下方式:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
        <phase>validate</phase>
        <configuration>
            <tasks>
            <mkdir dir="${project.build.directory}/yy" />                     
            <scp file="user:password@host:/home/xx/yy/*" todir="${project.build.directory}/yy" trust="yes"/>
            </tasks>
        </configuration>
        <goals>
            <goal>run</goal>
        </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-jsch</artifactId>
            <version>1.7.1</version>
        </dependency>
    </dependencies>
</plugin>   

如果我對用戶名和密碼進行硬編碼,它也可以工作。 但我不想在代碼庫中公開它。 所以我將它存儲在 maven-settings.xml 中,如下所示:

pom.xml

<scp file="${scpUserName}:${scpUserPassword}@company.net:/home/xx/yy/*" todir="${project.build.directory}/yy" trust="yes"/>

設置.xml

<profiles>
    <profile>
        <id>unix</id>
        <activation>
            <os>
                <family>unix</family>
            </os>           
        </activation>
        <properties>
            <scpUserName>xxx</scpUserName>
            <scpUserPassword>xxx</scpUserPassword>
        </properties>
    </profile>
</profiles> 

但是我仍然需要在 Teamcity 服務器中公開用戶名/密碼,以便所有代理服務器都可以成功構建整個項目。 我想知道是否有更好的方法?

Maven 文檔解釋了。 首先創建一個主密碼

mvn --encrypt-master-password <password>

將結果輸入settings-security.xml

<settingsSecurity>
  <master>the result here</master>
</settingsSecurity>

對於個人密碼,像這樣加密

mvn --encrypt-password <password>

你可以直接在你的 Maven 插件中使用它

<properties>
    <scpUserName>xxx<sscpUserName>
    <scpUserPassword>the result here</scpUserPassword>
</properties>

當您的構建服務器調用 Maven 時,您需要提供主密碼。 您可以通過使用密碼庫或其他東西存儲密碼來實現

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM