Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: Publish over SSH after failed build

Tags:

ssh

jenkins

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?

like image 226
laffoyb Avatar asked Oct 19 '25 09:10

laffoyb


1 Answers

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}
like image 175
laffoyb Avatar answered Oct 22 '25 03:10

laffoyb