Question

Je suis en train de copier les ressources vers un autre emplacement. J'utilise le plugin wagon-ssh Maven pour le faire. Il fonctionne très bien localement, j'ai des problèmes lors de l'utilisation d'Hudson / Jenkins.

Mon fichier settings.xml ressemble à ceci:

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

J'ai essayé cette réponse à sauter la vérification que je recevais:

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.

mais maintenant je reçois:

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.
Était-ce utile?

La solution

maven nécessite apparemment une entrée ssh-rsa dans le fichier known_hosts pour l'utilisateur de jenkins. Vous pouvez ajouter l'entrée ssh-rsa au dossier par l'émission:

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

[[Ajout d'une autre réponse à faire celui-ci définitive. ]]

Au lieu de cela, vous pourriez être en mesure d'ajouter ce qui suit à la ~jenkins/.ssh/config. Voir: Comment éviter Maven construit décrochage sur le problème de l'authenticité hôte ssh?

StrictHostKeyChecking no

Autres conseils

Le problème était que les clés RSA ont pas été échangés.

ce que je faisais était, je connecté à la fois les serveurs de ligne de commande. Ainsi, les clés RSA ont été stockées et

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.

ce message est arrêté. Il fonctionne parfaitement maintenant

est ce que nous utilisons dans le fichier known_hosts sur Populate nœud jenkins:

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

Il semble fonctionner assez bien.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top