Jenkins 服务器上的文件的 Jenkins scp 权限被拒绝
Jenkins scp permission denied for file on Jenkins server
我正在尝试将文件(在 SCM 结帐期间创建)从我的 Jenkins 代理复制到远程服务器。我已经设置了到远程服务器的 SSH,并且能够连接到它。我在 Jenkins 代理(不是远程主机)上收到文件的“权限被拒绝”错误。
我检查了文件的所有权,也尝试更改权限,但这没有用。
我的管道:
pipeline {
agent { label projectName }
stages {
stage("SCM: Checkout"){
steps{
script{
def gitURL="https://xxx.xxxxx.net/bitbucket/scm/project/text_preprocessor.git"
log.outputBanner("Checking out from the SCM")
scmSteps.cloneRepository(gitURL, env.BRANCH_NAME, credentialsId)
sh "ls -l"
sh "chmod +x docker-compose.yml" //changing permissions
sh "ls -l"
}
}
}
stage("Copy files") {
steps {
script{
sshagent (credentials: [prodServerCredentialId]) {
sh "ssh -o StrictHostKeyChecking=no -l user0 host.xxx.net 'ls'"
sh '''
scp -o StrictHostKeyChecking=no docker-compose.yml user0@host.xxx.net:/
'''
sh "ssh -o StrictHostKeyChecking=no -l user0 host.xxx.net 'ls'"
}
}
}
}
}
构建的输出显示如下(为清楚起见删除了一些信息部分):
[Pipeline] checkout
...
[Pipeline] sh
+ ls -l
total 20
drwxrwxr-x 2 user1 user1 4096 May 9 13:38 __pycache__
-rw-rw-r-- 1 user1 user1 385 May 9 13:38 docker-compose.prod.yml
-rw-rw-r-- 1 user1 user1 214 May 9 13:38 docker-compose.yml
drwxrwxr-x 3 user1 user1 4096 May 9 13:38 jenkinsfiles
drwxrwxr-x 4 user1 user1 4096 May 9 13:38 services
[Pipeline] sh
...
+ chmod +x docker-compose.yml
[Pipeline] sh
+ ls -l
total 20
drwxrwxr-x 2 user1 user1 4096 May 9 13:38 __pycache__
-rw-rw-r-- 1 user1 user1 385 May 9 13:38 docker-compose.prod.yml
-rwxrwxr-x 1 user1 user1 214 May 9 13:38 docker-compose.yml
drwxrwxr-x 3 user1 user1 4096 May 9 13:38 jenkinsfiles
drwxrwxr-x 4 user1 user1 4096 May 9 13:38 services
...
[Pipeline] sshagent
[ssh-agent] Using credentials user0 (Prod)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-FQIEn7xpUfkE/agent.608892
SSH_AGENT_PID=608894
Running ssh-add (command line suppressed)
...
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ ssh -o StrictHostKeyChecking=no -l user0 host.xxx.net ls
bin
docker-compose
[Pipeline] sh
+ scp -o StrictHostKeyChecking=no docker-compose.yml user0@host.xxx.net:/
scp: /docker-compose.yml: Permission denied
[Pipeline] }
原来是远程主机的权限错误。问题是我试图写入远程主机上我没有写入权限的位置。使用 user0@host.xxx.net:/ 我试图写入远程主机的根目录。我在远程服务器 (user0) 上我的用户的主文件夹中创建了一个临时文件夹,并通过更改成功地将文件复制到那里:
scp -o StrictHostKeyChecking=no docker-compose.yml user0@host.xxx.net:/
至
scp -o StrictHostKeyChecking=no docker-compose.yml user0@host.xxx.net:/home/user0/temp
我正在尝试将文件(在 SCM 结帐期间创建)从我的 Jenkins 代理复制到远程服务器。我已经设置了到远程服务器的 SSH,并且能够连接到它。我在 Jenkins 代理(不是远程主机)上收到文件的“权限被拒绝”错误。
我检查了文件的所有权,也尝试更改权限,但这没有用。
我的管道:
pipeline {
agent { label projectName }
stages {
stage("SCM: Checkout"){
steps{
script{
def gitURL="https://xxx.xxxxx.net/bitbucket/scm/project/text_preprocessor.git"
log.outputBanner("Checking out from the SCM")
scmSteps.cloneRepository(gitURL, env.BRANCH_NAME, credentialsId)
sh "ls -l"
sh "chmod +x docker-compose.yml" //changing permissions
sh "ls -l"
}
}
}
stage("Copy files") {
steps {
script{
sshagent (credentials: [prodServerCredentialId]) {
sh "ssh -o StrictHostKeyChecking=no -l user0 host.xxx.net 'ls'"
sh '''
scp -o StrictHostKeyChecking=no docker-compose.yml user0@host.xxx.net:/
'''
sh "ssh -o StrictHostKeyChecking=no -l user0 host.xxx.net 'ls'"
}
}
}
}
}
构建的输出显示如下(为清楚起见删除了一些信息部分):
[Pipeline] checkout
...
[Pipeline] sh
+ ls -l
total 20
drwxrwxr-x 2 user1 user1 4096 May 9 13:38 __pycache__
-rw-rw-r-- 1 user1 user1 385 May 9 13:38 docker-compose.prod.yml
-rw-rw-r-- 1 user1 user1 214 May 9 13:38 docker-compose.yml
drwxrwxr-x 3 user1 user1 4096 May 9 13:38 jenkinsfiles
drwxrwxr-x 4 user1 user1 4096 May 9 13:38 services
[Pipeline] sh
...
+ chmod +x docker-compose.yml
[Pipeline] sh
+ ls -l
total 20
drwxrwxr-x 2 user1 user1 4096 May 9 13:38 __pycache__
-rw-rw-r-- 1 user1 user1 385 May 9 13:38 docker-compose.prod.yml
-rwxrwxr-x 1 user1 user1 214 May 9 13:38 docker-compose.yml
drwxrwxr-x 3 user1 user1 4096 May 9 13:38 jenkinsfiles
drwxrwxr-x 4 user1 user1 4096 May 9 13:38 services
...
[Pipeline] sshagent
[ssh-agent] Using credentials user0 (Prod)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-FQIEn7xpUfkE/agent.608892
SSH_AGENT_PID=608894
Running ssh-add (command line suppressed)
...
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ ssh -o StrictHostKeyChecking=no -l user0 host.xxx.net ls
bin
docker-compose
[Pipeline] sh
+ scp -o StrictHostKeyChecking=no docker-compose.yml user0@host.xxx.net:/
scp: /docker-compose.yml: Permission denied
[Pipeline] }
原来是远程主机的权限错误。问题是我试图写入远程主机上我没有写入权限的位置。使用 user0@host.xxx.net:/ 我试图写入远程主机的根目录。我在远程服务器 (user0) 上我的用户的主文件夹中创建了一个临时文件夹,并通过更改成功地将文件复制到那里:
scp -o StrictHostKeyChecking=no docker-compose.yml user0@host.xxx.net:/
至
scp -o StrictHostKeyChecking=no docker-compose.yml user0@host.xxx.net:/home/user0/temp