欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jenkins通過sshPut傳輸文件時報錯Permission?denied的SftpException的問題及解決方案

 更新時間:2023年08月02日 10:20:09   作者:天草二十六_簡村人  
使用jenkins的ssh插件傳輸文件至遠程機器的指定目錄,php程序打包后,經(jīng)過zip壓縮為oms.zip,這篇文章主要介紹了jenkins通過sshPut傳輸文件的時候,報錯Permission?denied的SftpException,需要的朋友可以參考下

一、背景

使用jenkins的ssh插件傳輸文件至遠程機器的指定目錄,php程序打包后,經(jīng)過zip壓縮為oms.zip

zip -rq oms.zip ./ -x '.git/*' -x .env

然后我們求md5值

md5sum oms.zip

最后執(zhí)行傳輸。

09:03:02  Executing command on ssh[116.61.10.149]: mkdir -p /opt/php/oms sudo: false
[Pipeline] sshPut
[Pipeline] }
09:03:07  Sending a file/directory to ssh[116.61.10.149]: from: /home/jenkins/agent/workspace/PROD_resource_php_oms/oms.zip into: /opt/php/oms
09:03:08  Failed SFTP PUT: /home/jenkins/agent/workspace/PROD_resource_php_oms/oms.zip -> ssh:/opt/php/oms

二、報錯詳情

Caused: org.hidetake.groovy.ssh.operation.SftpException: Failed SFTP PUT: /home/jenkins/agent/workspace/PROD_resource_php_oms/oms.zip -> ssh:/opt/php/oms: (SSH_FX_PERMISSION_DENIED: The user does not have sufficient permissions to perform the operation): Permission denied

三、ssh pipeline

    def remote = [:]
    remote.name = 'ssh'
    remote.host = '116.61.10.149'
    remote.port = 22
    remote.allowAnyHosts = true
    def credentialsId = "285a0928-f35f-4485-a54f-48321aea7212"
withCredentials([sshUserPrivateKey(credentialsId: credentialsId, keyFileVariable: 'identity', passphraseVariable: '')]) {
        remote.user = 'phpuser'
        remote.identityFile = identity
        // 創(chuàng)建遠程目錄
        sshCommand remote: remote, command: "mkdir -p " + remoteFilePath
       // 上傳jar或者zip包,以及md5文件
        sshPut remote: remote, from: jarFileName, into: remoteFilePath
        sshPut remote: remote, from: md5FileName, into: remoteFilePath
        // 如果是zip壓縮文件,額外上傳一個.version文件,內(nèi)容是版本號
        if (".zip" == fileType) {
            sshPut remote: remote, from: ".version", into: remoteFilePath
        }
    }

四、排查過程

手動登錄遠程機器116.61.10.149,然后進入目標目錄,查看目錄所屬的用戶是root,而非phpuser,所以報沒有權(quán)限的錯誤。

[root@TEST-jekines ~]# ssh phpuser@116.61.10.149
Last login: Thu Jul 28 09:52:44 2022 from 116.61.10.149
Welcome to Alibaba Cloud Elastic Compute Service !
[phpuser@awx-pre ~]$ cd /opt/php
[phpuser@awx-pre php]$ ll
total 15
drwxr-xr-x 2 root root 4096 Jul 25 09:51 oms

查看文件夾的詳情

[phpuser@awx-pre php]$ stat oms
  File: ‘oms'
  Size: 4096            Blocks: 1          IO Block: 16384  directory
Device: 56h/86d Inode: 6993897     Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-07-25 09:51:29.613946996 +0800
Modify: 2023-07-25 09:51:29.613946996 +0800
Change: 2023-07-25 09:51:29.613946996 +0800
 Birth: -

文件夾oms是在2023-07-25 09:51:29由用戶root創(chuàng)建的,所以當phpuser用戶來嘗試創(chuàng)建目錄的時候,會失敗,繼而傳輸文件也報權(quán)限非法的錯誤。

五、解決問題

rm -rf /opt/php
  • 刪除后,目錄/opt/php下為空
  • 重試上傳文件
[phpuser@awx-pre oms]$ ll -h
total 170M
-rw-rw-r-- 1 phpuser phpuser 170M Jul 31 10:06 oms.zip
-rw-rw-r-- 1 phpuser phpuser   33 Jul 31 10:06 oms.zip.md5

到此這篇關(guān)于jenkins通過sshPut傳輸文件的時候,報錯Permission denied的SftpException的文章就介紹到這了,更多相關(guān)jenkins通過sshPut傳輸文件報錯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論