3
votes

I am trying to use the Publish Over SSH plugin to publish many kinds of build artifact to an external server. Examples of build artifacts are compiled builds, XML output from testing, and JSON output from linting.

If testing or linting results in errors, the build will fail or be marked unstable. In the case of a failed build, the Publish Over SSH plugin will not copy the build artifacts, writing to the console:

SSH: Current build result is [FAILURE], not going to run.

I see no reason why I wouldn't want to publish this information if it exists, and I would like to continue to report errors as build failures. So, is there any way to force Jenkins to publish build artifacts even if the job is marked as a failure?

I thought I could use the Flexible Publish to force this, by wrapping the Publish Over SSH in an "always" condition, but this gave the same output as before on a build failure.

I can think of a couple of work-arounds:

a) store the build status in an environment variable; force the status to SUCCESS; perform the publish step; recover the build status from the environment variable using java jenkins-cli.jar set-build-status $STORED_STATUS

OR

b) Write a bash script to perform the publishing step manually using SSH, cutting out the Publish Over SSH plugin altogether

Before I push forward with either of these solutions (neither of which I like), is there any piece of configuration that I'm missing?

2
I worked around this problem using the second option I prescribed above. A simple rsync command in a Post Script Task in my Jenkins job. If nobody can suggest a fix for the plugin, I will add this as an answer in a few days. - laffoyb

2 Answers

3
votes

The solution I ended up using was to use rsync/ssh to copy the files manually using a post build script. I configured this in my Jenkins Job Builder YAML like so:

- publisher:
    name: publish-to-archive
    publishers:
        - post-tasks:
            - matches:
                - log-text: ".*"
              script: |
                  ssh -i ${{HOME}}/.ssh/id_rsa jenkins@archiver "mkdir -p {archive_path}"
                  rsync -Pravdtze "ssh -i ${{HOME}}/.ssh/id_rsa" {source_path} jenkins@archiver:{archive_path}
3
votes

Quoting old hooky on jenkinsci-users:

How can I force Publish Over SSH to work even if the build has been marked a failure?

Use "Send files or execute commands over SSH after the build runs" in
configuration section "Build environment"

Job configuration / Build Environment / Send files or execute commands over SSH after the build runs

instead of using a post-build or build-step.