Install Packages Using a Jenkins Job Help

Hi @Ayman and everyone,

Could anyone point me towards a tutorial that could give me some guidance on how to complete the task Install Packages Using a Jenkins Job? I have tried several configurations (and plugins) and nothing that I have tried is working.

Thanks in advance to anyone who can help:-)

ps. Here are the steps that I attempted via my most recent attempt:

 # install plugin + update other plugins
 SSH Build Wrappers

 Jenkins --> Manage Jenkins --> Credentials --> add credentials 
 # Add username and password credentials from each app server

 Jenkins --> Manage Jenkins --> configure system --> go to section ( ssh remote hosts) -- add three hostnames + port 22

 # add each user to sudo user file
 ssh tony@stapp01     Ir0nM@n  
 sudo visudo
 # add
 tony   ALL=(ALL) NOPASSWD: ALL

 ssh steve@stapp02    Am3ric@ 
 sudo visudo
 # add
 steve   ALL=(ALL) NOPASSWD: ALL

 ssh banner@stapp03    BigGr33n 
 sudo visudo
 # add
 banner   ALL=(ALL) NOPASSWD: ALL

# Create a freestyle job 

# add build step => execute shell script via ssh
# choose host/ssh site for each host => note: UI sticks at 1st attempt

# add script to each host
sudo yum -y install epel-release yum-utils
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-71.rpm
sudo yum-config-manager --enable remi-php71
sudo yum -y install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

# install httpd
sudo yum -y update httpd
sudo yum -y install httpd
systemctl start httpd

# configure apache and restart the server
sudo sed -i "s/80/8086/g" /etc/httpd/conf/httpd.conf
sudo systemctl restart httpd
# end script

At this point I am getting an error and my job fails to build:

....build failed
Exception:java.net.ConnectException: Connection timed out (Connection timed out)

…some screenshots for reference:

Any help would be appreciated.

Thanks in advance to anyone who can help:-)

hi @juliettet, install java on app servers, then try again.

Hi @rahul456,

Here is the console output from my latest script:

Started by user Admin User
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/httpd-php
[SSH] commands:
# Install Java
sudo yum update
sudo yum install openjdk-8-dbg
java -version
# install on each server via build => add build step => execute shell script via ssh
# choose host/ssh site for each host => note: UI sticks
sudo yum -y install epel-release yum-utils
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-72.rpm
sudo yum-config-manager --enable remi-php72
sudo yum -y install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
## install httpd
sudo yum -y update httpd
sudo yum -y install httpd
systemctl start httpd
# configure apache and reload the server
sudo sed '0,/80/{s/80/3004/}' /etc/httpd/conf/httpd.conf
sudo systemctl restart httpd

…which still results in an error/timeout:

[SSH] executing...
[SSH] Exception:java.net.ConnectException: Connection timed out (Connection timed out)
com.jcraft.jsch.JSchException: java.net.ConnectException: Connection timed out (Connection timed out)
	at com.jcraft.jsch.Util.createSocket(Util.java:349)
	at com.jcraft.jsch.Session.connect(Session.java:215)
	at org.jvnet.hudson.plugins.CredentialsSSHSite.createSession(CredentialsSSHSite.java:132)
	at org.jvnet.hudson.plugins.CredentialsSSHSite.executeCommand(CredentialsSSHSite.java:208)
	at org.jvnet.hudson.plugins.SSHBuilder.perform(SSHBuilder.java:104)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
	at hudson.model.Build$BuildExecution.build(Build.java:206)
	at hudson.model.Build$BuildExecution.doRun(Build.java:163)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
	at hudson.model.Run.execute(Run.java:1894)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:428)
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at java.net.Socket.connect(Socket.java:538)
	at java.net.Socket.<init>(Socket.java:434)
	at java.net.Socket.<init>(Socket.java:211)
	at com.jcraft.jsch.Util.createSocket(Util.java:343)
	... 13 more
Build step 'Execute shell script on remote host using ssh' marked build as failure
Finished: FAILURE

I also noticed that I am not able to ssh into the jenkins server from jump host via ssh root@jenkins with the password S3curePass.

I’m not sure what to do next.

PS.

@rahul456,

Am I supposed to install Java manually on all 3 app servers or via the script(s) assigned to each server via the Jenkins job?

Thanks:-)

Yes… Install java on all app servers

1 Like

hi @juliettet, please try to record the solution, and share (Direct Message) the video if the issue occurs again.

1 Like

Thanks @tgp,

Manually (ie., not via the Jenkins UI) or via the job that runs the script via the Jenkins interface?

Hi @rahul456,

Thank you for responding. I will try to do that:-)

Hi again @rahul456,

I am still encountering the same issue. I have made a recording. I am going to send you the link via a direct message.

Cheers:-)

@juliettet. please add -y in your both commands i.e sudo yum update -y and sudo yum install java -y

1 Like

Hi @rahul456,

Thank you for responding. Unfortunately, that has not resolved the issue:

I have taken the exact same steps as the link to the video link that I sent you . The only thing that is different this time around is the addition of -y in the first two commands + I moved -y to the end of each command.

@juliettet, use hostname stapp01 instead of stapp01.stratos.xfusioncorp.com, then try it again and make sure to click on check connection to check the status.

1 Like

Hi @rahul456,

The job ran a bit longer this time, but it still ultimately led to an error:

Update:

…hang on…think I’ve got it…be back in a bit with an update:-)

OK. Here is an update:

Status Failed!!

…but httpd is running on App Server 1 & on all App Servers…

…more screenshots…

  • App Server 2:

  • App Server 3:

  • Job succeeded:

  • Successfully loaded PHP info page:

Update #2:

My latest script (without installing Java):

sudo yum -y install epel-release yum-utils

sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

sudo yum-config-manager --enable remi-php73

sudo yum -y install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd

sudo yum -y update httpd

sudo yum -y install httpd

sudo sed -i "s/80/3000/g" /etc/httpd/conf/httpd.conf

sudo systemctl restart httpd

My old script (…build always failed with this…)

sudo yum update -y

sudo yum install java-11-openjdk-devel -y

java -version

sudo yum install epel-release yum-utils -y

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-73.rpm -y

sudo yum-config-manager --enable remi-php72 -y

sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd -y

# install httpd

sudo yum update httpd -y

sudo yum install httpd -y

systemctl start httpd

sudo sed '0,/80/s//3000/' /etc/httpd/conf/httpd.conf

sudo systemctl restart httpd

# End script

@juliettet, marked pending for you, give it another try, and please do not tick this option, your latest script is working fine.

1 Like

Thanks @rahul456,

I’m pretty sure that this did the trick. However, I still failed again.

The error was that I did not have php 7.0 installed.

I think that the error was that I had not added the 0 here:

sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

sudo yum-config-manager --enable **remi-php7** 

…when I suppose that I should have had:

sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

sudo yum-config-manager --enable **remi-php70**

…weird…because I just assumed that the zero would not be needed here…because the task (this time) was not asking for .1 or .2 , etc…

I don’t mean to be a pain, but If that is all that caused the task to fail this time, could I please get a pass on this one? Everything was working and the job ran just fine.

I’ll be happy to move on from this.

Thanks again for your time and patience:-)

You are right about the line sudo yum-config-manager --enable remi-php7 being the one that is incorrect. I have also added the comment in your review along with some guidance on the task. Have a look:
Task Review

1 Like

I give up. It failed again. At this point I believe that there is an error in the validation. There HAS to be:

My (latest) script for all 3 servers:

sudo yum -y install epel-release
sudo yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum install -y yum-utils
sudo yum-config-manager --enable remi-php71
sudo yum install -y php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd httpd
sudo sed -i 's/^Listen 80$/Listen 8087/g' /etc/httpd/conf/httpd.conf
sudo systemctl restart httpd
sudo systemctl status httpd

Screenshots showing that job ran (…ran it several times to be sure) and that everything is/was working as expected:

How is this NOT a validation error?

:upside_down_face:

PS:

All steps that I had taken previously (ie., prior to running the job several times) remain the same:

# install plugin + update other plugins
SSH Build Wrappers

Jenkins --> Manage Jenkins --> Credentials --> add credentials
# Add username and pass to the three app servers
tony   Ir0nM@n
steve   Am3ric@
banner  BigGr33n

# Jenkins --> Manage Jenkins --> configure system --> go to section ( ssh remote hosts) -- add three hostnames + port 22

stapp01
stapp02
stapp03

# add each user to sudo user file on each app server after adding credentials via Jenkins UI

# thor password => mjolnir123
# add @ end
ssh tony@stapp01     Ir0nM@n  
sudo visudo
# add
tony ALL=(ALL) NOPASSWD: ALL   

ssh steve@stapp02    Am3ric@
sudo visudo
# add
steve ALL=(ALL) NOPASSWD: ALL

ssh banner@stapp03    BigGr33n
# add
sudo visudo
banner ALL=(ALL) NOPASSWD: ALL

Ah! Now that certainly looks like a validation error. The PHPInfo page is also showing Apache response from stapp03. Interesting to see the response from KKE team.

hi @juliettet, sorry for the issue, this is marked success for you.

1 Like

Hi @rahul456,

Thanks for looking into this. Hopefully the issue with the validation will be resolved so no one else has to encounter this.