I am working on a staging deployment with Jenkins.
What I am doing is, there are 3 pipelines
- for running the tests and quality checks etc
- for building a debian package and copying the artifacts on remote server
- installing that debian package etc
Everything is working fine, except in 2nd pipeline when copying the built debian package to remote server, I am getting this error:
[2024-03-18T13:12:42.832Z] Sending a file/directory to oauth-web02.b2bapi-stg.ovh.cloud.de[oauth-web02.b2bapi-stg.ovh.cloud.de]: from: /var/lib/jenkins/workspace/b2b-oauth-new/Oauth-server-Packager/b2b-oauth-server-new-staging_1.0.25_all.deb into: /home/b2bapiadm/b2b-oauth-server-new/
[2024-03-18T13:12:44.659Z] Failed SFTP PUT: /var/lib/jenkins/workspace/b2b-oauth-new/Oauth-server-Packager/b2b-oauth-server-new-staging_1.0.25_all.deb -> oauth-web02.b2bapi-stg.ovh.cloud.de:/home/b2bapiadm/b2b-oauth-server-new/
Failed SFTP PUT: /var/lib/jenkins/workspace/b2b-oauth-new/Oauth-server-Packager/b2b-oauth-server-new-staging_1.0.25_all.deb -> oauth-web02.b2bapi-stg.ovh.fti-cloud.de:/home/b2bapiadm/b2b-oauth-server-new/: (SSH_FX_FAILURE: An error occurred): Failure
Here is my groovy file snippet for that particular step:
stage('Deploying to staging') {
steps {
script{
for(int i=0; i< pipelineParams.STG_SERVER_CONFIG_NAME.size(); i++){
echo "Deploying ${pipelineParams.STG_SERVER_CONFIG_NAME[i]}"
def remote = [:]
remote.name = "${pipelineParams.STG_SERVER_CONFIG_NAME[i]}"
remote.host = "${pipelineParams.STG_SERVER_CONFIG_NAME[i]}"
remote.allowAnyHosts = true
withCredentials([
sshUserPrivateKey(
credentialsId: "${JENKINS_SSH_KEY_ID}",
keyFileVariable: 'identity',
passphraseVariable: '',
usernameVariable: 'userName'
)
]) {
remote.user = userName
remote.identityFile = identity
sshPut remote: remote,
from: "${ARTIFACTS_NAME_PREFIX}-staging_${BuildTag}_all.deb",
into: "${DEB_FILE_PATH}${ARTIFACTS_NAME_PREFIX}/",
dryRun: env.DRY_RUN
}
}
}
}
}
Debian built is fine, as I can see the artifacts:

Debian built process is fine as well:

The same pipeline is wokring fine with another project, and this project is a clone of that project.
I don't know if there is some missing configurations in Jenkins node.
Any help on input will be highly appreciated.
Regards,
So, after spending a lot of time in debugging, I am able to fix this issue for myself so adding the answer for you guys.
As the error does not say much so I tried all the possible solutions that I could find on the internet.
In my case, the directory /b2b-oauth-server-new I was trying to upload into was not found. So I created the directory on the remote server and all started working.