Jenkins SFTP Failed in deployment stage with sshPut to remote server

29 Views Asked by At

I am working on a staging deployment with Jenkins.

What I am doing is, there are 3 pipelines

  1. for running the tests and quality checks etc
  2. for building a debian package and copying the artifacts on remote server
  3. 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: enter image description here

Debian built process is fine as well: enter image description here

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,

1

There are 1 best solutions below

0
Airish On

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.

  • Check the disk space on remote server, In my case it was not the issue
  • Check if the Jenkins deployer user has necessary permissions to upload on remote server, that was fine as well in my case

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.