Recently I have been messing around with Docker/Jenkins to learn more about CI/CD workflows. I am aiming to have a process that takes pushes from github, builds the code and releases a JAR file to a remote server for further deployment.
I have been using the Jenkins SSH Pipeline Steps Plugin which has allowed me to SSH into my remote server to execute commands.
Here is the Deployment stage which involves the commands that I want to execute:
stage("Deploying") {
steps {
script {
withCredentials([sshUserPrivateKey(credentialsId: 'e48b15ad-0f5e-4f07-8706-635c5250fa29', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'jenkins')]) {
remote.user = jenkins
remote.identityFile = identity
sshCommand remote: remote, command: 'cd Winston-Bot/; sudo ./kill_winston.sh'
sshCommand remote: remote, command: 'rm Winston-Bot/*.jar', failOnError:'false'
sshCommand remote: remote, command: 'rm -rf Winston-Bot/src', failOnError:'false'
sshPut remote: remote, from: "target/Winston-Bot-${VERSION}-jar-with-dependencies.jar", into: 'Winston-Bot/'
sshPut remote: remote, from: "src", into: 'Winston-Bot/'
sshCommand remote: remote, command: "echo ${VERSION} > Winston-Bot/version.txt"
}
}
}
}
When executing cd Winston-Bot/; sudo ./kill_winston.sh
I receive the following error:
Executing command on ****[51.159.152.230]: cd Winston-Bot/; sudo ./kill_winston.sh sudo: false
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
Failed command ****#15 with status 1: cd Winston-Bot/; sudo ./kill_winston.sh
I have already added the jenkins user group to the etc/sudoers
with the following code:
jenkins ALL=(ALL) NOPASSWD: /var/lib/jenkins/Winston-Bot/.kill_winston.sh
The script executes perfectly fine when logged into my remote server as user jenkins
through a terminal and does not require a password. Can anyone help me out with this?