Reputation: 2962
My Jenkins job is supposed to run scripts.
These scripts need to perform commands as other users. Here is an example:
/usr/bin/su -c "/usr/bin/hive -e \"$QR_TABLE_DELETION\"" hive
However, when running the script that contains this, I get the following error:
Password: Password: su: Authentication failure
How am I supposed to run scripts that must be able to run commands as another user with Jenkins ?
JenkinsFile:
pipeline {
agent any
stages {
stage ('QR GOLD TABLE DELETION/CREATION') {
steps {
sh 'chmod +x ./load/bin/1.1.1_quality_results'
sh './load/bin/1.1.1_quality_results'
}
}
stage ('Finish') {
steps {
echo 'End'
}
}
}
}
Edit: './load/bin/1.1.1_quality_results' contains the command that must be run as another user.
Upvotes: 1
Views: 4501
Reputation: 1056
Well, an easy solution would be to create a node that runs as the user on the appropriate host. Then, in the jenkinsfile, simply tell Jenkins to invoke the stage using that node. In the steps, perform the command (without the SU).
1.) Create node as user. Create the node in Jenkins as you normally would - likely it should use 'Launch Method'='Launch Agents via SSH'. Specify the host (which could be localhost) and the provide credentials (username/password) for the user you are trying to 'su' as.
2.) Jenkinsfile. Would look something like:
pipeline {
agent { node { label 'SomeUserNode' } }
stages {
stage ('QR GOLD TABLE DELETION/CREATION - runs as user') {
steps {
sh '/usr/bin/hive -e \"$QR_TABLE_DELETION\"" hive'
}
}
stage ('Finish') {
steps {
echo 'End'
}
}
}
}
Upvotes: 0
Reputation: 2962
The solution I have chosen so far is to give specific sudo rights to the Jenkins user in order to allow him to use some commands like hive or hdfs.
Upvotes: 1