简体   繁体   中英

Maven Wagon plugin fails to upload over SCP despite return code 0

I'm maintaining a project using the Maven Wagon plugin to upload artifacts to a server where the organisation stores new releases of the application in question.

That server has changed a while back and I'm having a hard time getting the artifacts to start uploading again. Having updated the credentials and ensured that the server is reachable from our CI environment, I'm running into a strange issue.

[INFO] [DEBUG] Configuring mojo 'org.codehaus.mojo:wagon-maven-plugin:2.0.2:upload' with basic configurator -->
[INFO] [DEBUG]   (f) followSymLink = false
[INFO] [DEBUG]   (f) fromDir = /var/lib/jenkins/workspace/foo-release/target/checkout/cq5/foo-bar-assembly/target
[INFO] [DEBUG]   (f) includes = **/*.zip
[INFO] [DEBUG]   (f) optimize = false
[INFO] [DEBUG]   (f) project = MavenProject: com.example.noyb:foo-bar-assembly:1.1.1 @ /var/lib/jenkins/workspace/foo-release/target/checkout/cq5/foo-bar-assembly/pom.xml
[INFO] [DEBUG]   (f) serverId = release-server
[INFO] [DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@3abfe845
[INFO] [DEBUG]   (f) skip = false
[INFO] [DEBUG]   (f) toDir = 1.1.1
[INFO] [DEBUG]   (f) url = scp://192.168.50.20/mnt/somedir/foo-bar/releases
[INFO] [DEBUG]   (f) useDefaultExcludes = true
[INFO] [DEBUG] -- end configuration --
[INFO] Unable to connect to agent: com.jcraft.jsch.agentproxy.AgentProxyException: connector is not available: 
[INFO] scp://192.168.50.20/mnt/somedir/foo-bar/releases - Session: Opened  
[INFO] [INFO] Uploading /var/lib/jenkins/workspace/foo-release/target/checkout/cq5/foo-bar-assembly/target/foo-bar-1.1.1-config/foo-bar-config-1.1.1-cq.zip to scp://192.168.50.20/mnt/somedir/foo-bar/releases/1.1.1/foo-bar-1.1.1-config/foo-bar-config-1.1.1-cq.zip ...
[INFO] Executing command: mkdir -p "/mnt/somedir/foo-bar/releases/1.1.1/foo-bar-1.1.1-config"
[INFO] Executing command: mkdir -p "/mnt/somedir/foo-bar/releases/1.1.1/foo-bar-1.1.1-config"
[INFO] Executing: mkdir -p "/mnt/somedir/foo-bar/releases/1.1.1/foo-bar-1.1.1-config"
[INFO] Stdout results:
[INFO] Stderr results:/etc/profile.d/welcomer.sh: line 6: ip: command not found
[INFO] TERM environment variable not set.
[INFO] 
[INFO]  Transfer error: org.apache.maven.wagon.CommandExecutionException: Exit code: 0 - /etc/profile.d/welcomer.sh: line 6: ip: command not found
[INFO] TERM environment variable not set.
[INFO] 
[INFO]  Transfer error: org.apache.maven.wagon.TransferFailedException: Exit code: 0 - /etc/profile.d/welcomer.sh: line 6: ip: command not found
[INFO] TERM environment variable not set.
[INFO] 
[INFO] scp://192.168.50.20/mnt/somedir/foo-bar/releases - Session: Disconnecting  
[INFO] scp://192.168.50.20/mnt/somedir/foo-bar/releases - Session: Disconnected

The Maven build fails just after the above. No artifacts get uploaded to the server, but the folder into which they're supposed to be added gets created.

The output contains a number of executables that I don't believe the plugin to need or use. What's also puzzling is that the return code appears to be 0 , which isn't an error code. I'd expect that to be a positive number in case of an error.

I'm using

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>wagon-maven-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <!-- redacted -->
    </configuration>
    <executions>
        <execution>
            <id>upload-artifacts</id>
            <phase>deploy</phase>
            <goals>
                <goal>upload</goal>
            </goals>
        </execution>
    </executions>
</plugin>

and

<extension>
    <groupId>org.apache.maven.wagon</groupId>
    <artifactId>wagon-ssh</artifactId>
    <version>3.5.1</version>
</extension>

As it turns out, the new server has a welcome message displayed to any user logging on over SSH. That message displays its IP address, its name and a bit of guidance around its usage (eg where certain things can be found in the file system, etc.)

That message displays correctly when you access the server over SSH. However, for some reason, the script responsible for rendering the message also kicks in when scp is used to transfer files onto the server.

When scp , rather than ssh is used, the script rendering the message fails because it's apparently missing a path to an executable in the PATH variable. It also complains about not having the TERM variable set.

/etc/profile.d/welcomer.sh: line 6: ip: command not found
TERM environment variable not set.

That's the message accompanying both the CommandExecutionException and the TransferFailedException . I don't understand why the message kicks in when SCP is used or why it fails then. There's probably a way for the script to tell the difference. It seems, however, that it prints those messages to Stderr , which the Wagon SSH extension interprets as a failure, even though the errors have nothing to do with the commands the plugin itself executes. I think that's a fair design consideration, if an unanticipated error is present, stop execution. The most surprising bit is the return code 0 . I'm guessing this has to do with the only command actually invoked by the plugin (ie creation of the directory) actually succeeding, but it's based on pure speculation.

Disabling the welcome script allowed the plugin to succeed in uploading artifacts. We'll see about improving the welcome message in a way that will allow it to be used without preventing the Wagon plugin from successfully invoking scp .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM