[英]How to run "sudo su" command in Jenkins Declarative pipeline?
I have a strange situation where the shell command "sudo su" is not working as expected in Jenkins Declarative pipeline.我有一个奇怪的情况,shell 命令“sudo su”在 Jenkins 声明性管道中没有按预期工作。 Below is my code:
下面是我的代码:
stages {
stage('Ansible-dynamichost-generation') {
steps {
ansiColor('xterm') {
sh 'chmod -R 777 /home/jenkins-slave/'
sh 'sudo su ansible'
sh '''#!/bin/bash -l
#Execute commands
echo "$WORKSPACE"
whoami
'''
}
}
}
}
This pipeline is being run by a jenkins-slave user.该管道由 jenkins-slave 用户运行。 However, I have a shell command in pipeline that is supposed to switch to a user called "ansible".
但是,我在管道中有一个 shell 命令,它应该切换到一个名为“ansible”的用户。 But, when the "whoami" command is executed, it returns with an output of "jenkins-slave" itself.
但是,当执行“whoami”命令时,它会返回“jenkins-slave”本身的输出。 Can anyone help as to what is going wrong here ?
任何人都可以帮助了解这里出了什么问题吗?
each sh commands are execute in sperate sheel.每个 sh 命令都在单独的工作表中执行。 better write one sh and do the operation it will work
最好写一个 sh 并执行它会起作用的操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.