gpt4 book ai didi

java - 存储 Ant SCP 任务的用户名/密码的最佳方式是什么

转载 作者:行者123 更新时间:2023-12-01 18:18:11 38 4
gpt4 key购买 nike

我需要使用 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 documentation解释说。首先创建一个主密码

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 时,您将需要提供主密码。您可以通过使用 a password vault 存储密码来实现此目的或其他什么。

关于java - 存储 Ant SCP 任务的用户名/密码的最佳方式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60325368/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com