我正在尝试将资源复制到另一个位置。我正在使用Maven Wagon-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显然需要在 known_hosts 为Jenkins用户申请。您可以通过发行将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.

此消息停止了。它现在正常工作

这是我们用来在jenkins节点上填充已知_host文件的内容:

  <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>

似乎运作良好。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top