Please visit my website and subscribe to my youtube channel for more articles
Thank you for Subscribing! If you have not, Subscribe now! DevOps4Solutions helps in providing end to end solution and…
Login to AWS EC2 Linux Instance
Install Java : Click Here for more details
wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.rpmsudo yum localinstall jdk-8u171-linux-x64.rpmexport JAVA_HOME=/usr/java/jdk1.8.0_171/
sudo alternatives --config java
Install Jenkins : Click here for more details
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.reposudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.keysudo yum install jenkinssudo yum install gitsudo service jenkins start
Open the url in the browser. Default port is 8080
It will ask for the initial password, please run the below command
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Jenkins setup with windows agent is completed successfully.
Now to run any job on windows slave, you have to provide the label as “windows” in any Jenkins job as shown below
Integrate Jenkins with Gitlab
Go to GitLab ->Profile Settings
Then, click “Access Token” and create a Jenkins API Token
Then, save and copy this API Token. You won’t be able to access it again
Install Plugins in Jenkins
Manage Jenkins -> Manage Plugins -> Gitlab,gitlab hook,junit,testng results
Configure the Jenkins Server with Gitlab Server
Go to Manage Jenkins -> Configure System and scroll down to the ‘GitLab‘ section. Write a custom connection name, enter the GitLab server URL in the ‘GitLab host URL‘ field and click Add -> Jenkinsbutton.
Then, fill required fields as shown below with the Jenkins Access API Token which we created in GitLab before.
Then, select this API Token credential and finally click “Test” and see the “Success” message as shown below
Setup SSH connection between Jenkins and Gitlab
Run on Jenkin Server
sudo -su jenkinsssh-keygen
eval $(ssh-agent -s)
Go to Gitlab setting -> SSH Keys -> paste the key
Jenkins ->Credentials -> Add Crdentials -> SSH username with private key
Copy key from here cat /home/ec2-user/.ssh/id_rsa
SSH setup is completed successfully.
Configure Windows Agent to clone git repo.
Manage Jenkins -> Manage Nodes -> Windows Node — Configure -> Add Tools Location
Configure Java and Git ( Installed Java and Git manually on windows agent)
Configuring webhooks in GitLab
This will trigger the Jenkins job as an when there is a push in the repository
Go to specific project in gitlab-> click on settings ->integration as shown below
Put the jenkins job project url and all default setting
Click on test and push events
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 403 No valid crumb was included in the request</title>
<body><h2>HTTP ERROR 403</h2>
<p>Problem accessing /job/Test_php/. Reason:
<pre> No valid crumb was included in the request</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a><hr/></body>
</html>Error after comitting in gitlabNo need for this -> disable csrf in security
configure credential — for anonymous access
All configuration is setup successfully.
Now we will create a jenkins job for running selenium test case
Create a Freestyle job in Jenkins
Set Label that this job will run only on windows agent
Job Successfully completed. Click on Build now and see the results.
Setup for PHP Unit test cases
Install php and phpunit on linux jenkins server
sudo yum install php56wget https://phar.phpunit.de/phpunit-5.6.1.phar
php phpunit-5.6.1.phar — version
chmod +x phpunit-5.6.1.phar
sudo mv phpunit-5.6.1.phar /usr/local/bin/phpunit
Manage Plugins -> Junit (if not already installed)
Create a freestyle project
/usr/local/bin/phpunit — log-junit test.xml -c phpunit.xml .
Job is successfully setup.