I need use a scp task to transfer a whole folder with many sub-folders and files. Currently I use below way:
<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>
And it also works if I hard code username and password. But I don't want to make this public in code base. So I make it store in maven-settings.xml like below:
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>
But I still need make username/password public in Teamcity server so that all agent servers can build whole project successfully. I wonder if there are any better way for this?
Maven documentation explains. First create a master password
mvn --encrypt-master-password <password>
Enter the result into settings-security.xml
<settingsSecurity>
<master>the result here</master>
</settingsSecurity>
For the individual passwords, encrypt like this
mvn --encrypt-password <password>
And you can use it directly in your Maven plugin
<properties>
<scpUserName>xxx<sscpUserName>
<scpUserPassword>the result here</scpUserPassword>
</properties>
When your build server invokes Maven, you will need to supply the master password. You can do so by storing the password using a password vault or something.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.