Maven Wagon SCP无法建立连接



我正在尝试将资源复制到另一个位置。我使用maven货车ssh插件做到这一点。它在本地工作得很好,我在使用Hudson/Jenkins时遇到了问题。

我的settings.xml文件看起来像这样:

<servers>
    <server>
        <id>iq</id>
        <configuration>
            <knownHostsProvider implementation="org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider">
                <hostKeyChecking>no</hostKeyChecking>
            </knownHostsProvider>
        </configuration>
        <username>user</username>
        <password>pass</password>
    </server>
</servers>

我试着跳过这个答案,因为我得到:

Are you sure you want to continue connecting? (yes/no): The authenticity of host 'address' can't be established.
RSA key fingerprint is 10:.......:bb.

但现在我得到:

Could not apply configuration for iq to wagon org.apache.maven.wagon.providers.ssh.jsch.ScpWagon:ClassNotFoundException: Class name which was explicitly given in configuration using 'implementation' attribute: 'org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider' cannot be loaded
org.codehaus.plexus.component.configurator.ComponentConfigurationException: ClassNotFoundException: Class name which was explicitly given in configuration using 'implementation' attribute: 'org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider' cannot be loaded
    at org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter.getClassForImplementationHint(AbstractConfigurationConverter.java:70)
    at .....
Caused by: java.lang.ClassNotFoundException: org.apache.maven.wagon.providers.ssh.knownhost.NullKnownHostProvider
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    at org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter.getClassForImplementationHint(AbstractConfigurationConverter.java:61)
    ... 37 more
The authenticity of host 'address' can't be established.
RSA key fingerprint is 10:.......:bb.
Are you sure you want to continue connecting? (yes/no): The authenticity of host 'address' can't be established.

maven显然需要在jenkins用户的known_hosts文件中有一个ssh-rsa条目。您可以通过以下命令向文件添加ssh-rsa条目:

ssh-keyscan -t rsa YOUR_REMOTE_HOSTNAME >> ~jenkins/.ssh/known_hosts

[[从另一个答案中添加,使这个答案更明确。]]

相反,您可以将以下内容添加到~jenkins/.ssh/config中。参见:如何避免Maven构建在ssh主机真实性问题上停滞?

StrictHostKeyChecking no

问题是RSA密钥没有交换。

所以我所做的是,我从命令行连接两个服务器。RSA密钥存储起来了

Are you sure you want to continue connecting? (yes/no): The authenticity of host 'address' can't be established.
RSA key fingerprint is 10:.......:bb.

此消息已停止。现在可以正常工作了

Wagon-ssh将为您完成这项工作。不需要手工或脚本复制指纹。

settings.xml文件中禁用strict主机密钥检查

<servers>
    <server>
        <id>iq</id>
        <configuration>
            <StrictHostKeyChecking>no</StrictHostKeyChecking>
        </configuration>
        <username>user</username>
        <password>pass</password>
    </server>
</servers>

主机指纹被自动接受并存储在known_hosts文件中。验证过程的其余部分照常进行。

此命令在带有构建代理的Bamboo构建服务器上成功运行,构建代理具有自己的本地ssh配置文件。

这是我们用来在jenkins节点上填充known_hosts文件的:

  <plugin>
    <groupId>org.codehaus.groovy.maven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <executions>
      <execution>
          <id>check-known-hosts</id>
          <phase>initialize</phase>
          <goals>
            <goal>execute</goal>
          </goals>
          <configuration>
            <source>
                import com.jcraft.jsch.*;
                import org.apache.maven.wagon.providers.ssh.knownhost.*;
                def keyString = "<REPLACE_WITH_HOST_KEY>" // host key - the line from known_hosts after key type (ssh-rsa)
                FileKnownHostsProvider fkhp = new FileKnownHostsProvider();
                JSch sch = new JSch();
                sch.setKnownHosts(new ByteArrayInputStream(fkhp.getContents().getBytes()));
                def host = project.properties.serverAddress // define <serverAddress>someserveraddress.com</serverAddress> in <properties> 
                if (host != null) {
                  HostKeyRepository hkr = sch.getHostKeyRepository();
                  HostKey[] hk = hkr.getHostKey( host , null );
                  StringWriter stringWriter = new StringWriter();
                  String knownHost = host + " " + "ssh-rsa" + " " + keyString;
                  if ( hk != null )
                  {
                    PrintWriter w = new PrintWriter( stringWriter )
                    def containsKey = false;
                    for ( HostKey key : hk )
                    {
                      def toAdd =  key.getHost() + " " + key.getType() + " " + key.getKey();
                      w.println(toAdd)  ;
                      containsKey = knownHost.equals(toAdd);
                    }
                    if (!containsKey) {
                      println "Adding key for " + host + " to known_hosts"
                      w.println(knownHost);
                      fkhp.storeKnownHosts(stringWriter.toString() );
                    } else {
                      println "Key for " + host + " is already present in known_hosts"
                    }
                  }
                }
            </source>
          </configuration>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ssh-common</artifactId>
        <version>2.10</version>
      </dependency>
      <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.54</version>
      </dependency>
    </dependencies>
  </plugin>

看起来效果不错。

相关内容

  • 没有找到相关文章

最新更新