Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Pipelines: How to upload a jar to remote server using scp

ACV001 April 25, 2020

Hi,

I've tried all combinations, but I could not find a way to upload a maven generated jar file to a remote server using the scp pipeline.

If I use 

LOCAL_PATH: '${BITBUCKET_CLONE_DIR}/*'

this would copy the whole source folder structure , but without any trace of the target/ folder or any jar.

I tried this (it's a multi module project):

LOCAL_PATH: '${BITBUCKET_CLONE_DIR}/web/target/*'

 

The build finishes successfully and the logs say uploading artifact to maven repo from:

 

/opt/atlassian/pipelines/agent/build/web/target/

 

 But then when trying the scp:

 

/opt/atlassian/pipelines/agent/build/web/target/*.jar: No such file or directory

 Thank you

 

1 answer

1 accepted

0 votes
Answer accepted
ACV001 April 25, 2020

I've found the answer. It is simple. Basically, to share the artifacts produced by one step in the pipeline, with other steps, you need to use artifacts (https://confluence.atlassian.com/bitbucket/using-artifacts-in-steps-935389074.html)

 

Here's how I did it:

In the build step I declared artifacts:

pipelines:
default:
- step:
caches:
- maven
script: # Modify the commands below to build your repository.
- mvn -B install # -B batch mode makes Maven less verbose
- ls -R $BITBUCKET_CLONE_DIR # This will list all files in your build environment.
- ls -R $BITBUCKET_CLONE_DIR | xargs realpath
artifacts:
- '**/target/*.jar'

 

And then in the next step, I refer to them in the LOCAL_PATH variable of the scp-deploy pipe:

- step:
name: Deploy to server
deployment: Test
script:
- ls -R $BITBUCKET_CLONE_DIR # This will list all files in your build environment.
- ls -R $BITBUCKET_CLONE_DIR | xargs realpath
- pipe: atlassian/scp-deploy:0.3.11
variables:
USER: '${USER}'
SERVER: '${HOST}'
REMOTE_PATH: '/home/myuser/'
LOCAL_PATH: '**/target/*.jar'
- pipe: atlassian/ssh-run:0.2.5
variables:
SSH_USER: '${USER}'
SERVER: '${HOST}'
COMMAND: 'ls -l'

 The last command (in ssh-run ls -l) would show my jar files on the server.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events