【发布时间】:2020-06-05 02:23:05
【问题描述】:
我需要使用 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"/>
settings.xml
<profiles>
<profile>
<id>unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<scpUserName>xxx</scpUserName>
<scpUserPassword>xxx</scpUserPassword>
</properties>
</profile>
</profiles>
但我仍然需要在 Teamcity 服务器中公开用户名/密码,以便所有代理服务器都可以成功构建整个项目。不知道有没有更好的办法呢?
【问题讨论】:
-
生成 ssh 密钥,不存储密码。
-
@ElliottFrisch 感谢您的快速回答。但这是否意味着每个构建代理服务器也需要在构建之前安装该密钥?
-
安装 ssh 密钥需要在
$HOME/.ssh文件夹中放置两个文件,但是可以。比存储密码要好得多(更安全,更易于管理)。 -
@ElliottFrisch 但是 teamcity 代理服务器在我们公司是不受我们控制的。需要其他方式。谢谢。无论如何。
-
此传输是 CI 解决方案的工作,而不是 Maven。在您的构建管道中添加一个单独的步骤,让 Teamcity 解决这个问题……还可以使用 TeamCity 的机制来存储/处理凭据。这将使您的 Maven 构建更干净...