Compass compile on Jenkins CI - jenkins

I have the following execute script on my CI environment
cd /var/www/html
php vendor/bin/phpunit app/tests --log-junit /var/lib/jenkins/jobs/Closecall/workspace/tests/reports/junit.xml
php vendor/bin/phinx migrate -e development
sudo compass compile
SSHing onto the CI and compiling myself works fine, however when the CI executes this on build I get the following error
+ sudo compass compile
sudo: no tty present and no askpass program specified
Build step 'Execute shell' marked build as failure
Recording test results
Finished: FAILURE
Any ideas?

sudo by default tries to open /dev/tty for read-write. You might not have /dev/tty available on the machine you use to build. The need for tty is configured in the /etc/sudoers file.
sudo has an option -S to read the password from standard input instead of /dev/tty. You should be able to compile using sudo -S.
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.
http://linux.die.net/man/8/sudo

Related

pytest' is not recognized as an internal or external command, while executing through jenkins job

I am trying to run python test through jenkins. I have pytest framework.
I have also installed python 3.8 on jenkins slave machine and set path in the environment variables
I have added below path under PATH section of environment variable as below
C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\Scripts
C:\Users\Admin\AppData\Local\Programs\Python\Python38-32
But still I am getting below error on while running job.
Below are my windows batch command to run from Jenkins:
echo '#### Create Virtual Environment ####'
python -m venv .UIAutomation/venv
echo '#### Activate Virtual Environment ####'
echo '#### Run tests ####'
pytest -s -v --alluredir=.UIAutomation/reports ./UIAutomation/tests --env=staging --browser=chrome
Please help
More details about console error :
warning: manifest_maker: standard file '-c' not found
12:04:12 Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the directory
Note:
Below is my first requirement from file
Collecting psycopg2==2.8.6 (from -r ./UIAutomation/requirements.txt
So after execution I am seeing below error at first line of console-
12:04:12 Error: pg_config executable not found.
12:04:12 pg_config is required to build psycopg2 from source. Please add the directory
From what I see, I find the batch call suspicious.
I think call launches a new console and returns to the script, if its done. So in your case, you activate your venv in another console and then use your standard python env, not the venv and there is no pytest dependency installed.
See also: https://ss64.com/nt/call.html
I had a similiar problem in a yaml script I wrote for Azure DevOps.
I did solve that, with creating the venv and then adding the venv path to the environment variables.

Jenkins SSH Pipeline Steps - A terminal is required to read the password

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?
I'm not sure it will be relevant for you but I had the exact same problem on macOS Big Sur. No matter how I edited the sudoers file with sudo visudo it simply wouldn't work.
The moment I've created and edited the right file it started working immediately: sudo visudo -f /etc/sudoers.d/jenkins
jenkins ALL=(ALL) NOPASSWD: ALL
I've got the idea from this comment and this answer.
I had the same problem: works fine and am not prompted for sudo password while using SSH via a terminal, but when running via a Jenkins job using SSH keys, got the error:
sudo: a terminal is required to read the password; either use the -S
option to read from standard input or configure an askpass helper
sudo: a password is required
The fix proposed by #farkasseb works for me also, and is probably the best solution, especially given this note at the top of the sudoers file which encourages this:
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
But I still wanted to understand more about why this was happening. What I also found out is that it matters where (the location) in the visudo / sudoers file where I place:
jenkins ALL=(ALL) NOPASSWD: ALL
If it is placed directly after root, then the issue is reproduced via jenkins SSH but not via terminal SSH. If it is placed AFTER the definition of the %admin and %sudo group, then I am no longer prompted for password when running via jenkins.
So, moving the jenkins user declaration downwards in the sudoers file results in the following order of permissions when listing the permissions for the jenkins user using this command:
sudo -l -U jenkins
From this:
(ALL) NOPASSWD: ALL
(ALL : ALL) ALL
To this:
(ALL : ALL) ALL
(ALL) NOPASSWD: ALL
I'm assuming that because NOPASSWD is last, that it has precedence? The following is a complete snippet from the sudoers file which does not prompt for password via jenkins:
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# add in jenkins user AFTER the sudo and admin group
jenkins ALL=(ALL) NOPASSWD: ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
In the end, I can conclude that by using the sudo visudo -f /etc/sudoers.d/jenkins command to create a separate file that gets included by the #includedir /etc/sudoers.d results in the jenkins ALL=(ALL) NOPASSWD: ALL permission coming last too, which has the same effect as above.
What I still don't understand is why or how this could result in different behavior when running via Jenkins SSH vs terminal SSH?
In any event, if you don't want to modify the sudoers file directly, use the approach by #farkasseb (which has other advantages apparently when upgrading the OS). If it's OK for you to modify the sudoers file directly, then you can use this approach, just make sure the NOPASSWD part comes last, after the group definitions.

Jenkins/Robot Framework - looking for chromedriver but I think it's in PATH

Hey in Jenkins I'm trying to run robot framework tests:
with command python3 robot -d results mytestsuite.robot, and it has some line to open chrome browser, but the message in log shows me typical: WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see...
Everything works ok locally, and I'm not sure which PATH jenkins wants to use so my questions are:
why do I have to input python3 instead of python (with just python in command it tells me that robot is not found)
why chromedriver is not found, and how to set it up (in what PATH and how) to make it work
Is it possible to set jenkins up to use other drivers ex. geckodriver?
My jenkins job env looks like this:
#!/bin/bash
echo $JENKINS_HOME
which python3
echo $PATH
outputs:
/Users/MYUSER/.jenkins
/usr/bin/python3
/Users/MYUSER/.jenkins/tools/chromedriver:/usr/bin:/bin:/usr/sbin:/sbin
Ok so I've fixed it with:
export PATH=/Library/Frameworks/Python.framework/Versions/3.9/bin/:$PATH
this is the location where I have chromedriver locally.
in the build shell execute but is there a way to make it more permanent (I mean not to use it every time it runs build?)

Q: Why randomly getting 'sudo: no tty present and no askpass program specified' error in Jenkins?

We are running Jenkins in a docker container and using the Docker-outside-of-Docker approach. As is well documented, we added:
jenkins ALL=NOPASSWD: ALL
to /etc/sudoers.
http://container-solutions.com/running-docker-in-jenkins-in-docker/
How to fix 'sudo: no tty present and no askpass program specified' error?
The problem we face is that our pipeline job randomly fails when executing the first make command:
sudo -E make login
with the error:
sudo: no tty present and no askpass program specified
Why are we experiencing this error only sometimes?
If you get the issue like as mentioned below
error message image
Login to the instance in GitBash and open the following file.
sudo visudo
And in this file Add the following command in the end of the file
jenkins ALL=(ALL) NOPASSWD: ALL
Save the file and Run the Jenkins onnce again.
Hope your issue will be solve.
Thanks!
Image

fpm is not recognised if executing script with jenkins and ssh

I am trying to execute a script over ssh connexion with Jenkins. I am using the SSH plugin and it is well configured. I arrive to execute the first part of the script, but when I try to execute a fpm command it says:
fpm: command not found
If I connect to the instance and run the same script that I call via Jenkins it runs and there is no error (fpm is installed).
So, I have created a test like a script test.sh:
#!/bin/bash -x
fpm
but, with Jenkins, I get the same error: fpm: command not found, while if I execute it I get a normal "parameter needed":
Missing required -s flag. What package source did you want? {:level=>:warn}
Missing required -t flag. What package output did you want? {:level=>:warn}
No parameters given. You need to pass additional command arguments so that I know what you want to build packages from. For example, for '-s dir' you would pass a list of files and directories. For '-s gem' you would pass a one or more gems to package from. As a full example, this will make an rpm of the 'json' rubygem: `fpm -s gem -t rpm json` {:level=>:warn}
Fix the above problems, and you'll be rolling packages in no time! {:level=>:fatal}
What am I missing? Why it cannot find fpm if it is installed?
Make sure fpm is in /usr/bin..
It seems that the problem came because the fpm was installed in the /home/user2connect/bin/, and the command was not recognised. For fixing this I had to call it wit the whole path:
/home/user2connect/bin/fpm ...
I have chosen to reinstall the fpm using sudo, so now it works.

Resources