Jenkins Guide (MEC-based)
This section contains the guide to Jenkins.
General information - Jenkins:
Why do we need Jenkins?
To get approval of continuous integration continuous delivery/deployment (CICD) by the Akraino committee. i.e., By pushing the logs to Nexus Akraino Repository.
Who should push the logs? / Where should the logs be pushed?
- who/from: Jenkins setup in a lab (private/shared lab)
- where/to: Nexus Repository Manager - Akraino
Prerequisites:
Access to Nexus Akraino Repository. (How to get access of Nexus Akraino Repository?)
Jenkins for private lab:
Once you have completed the prerequisites. Now you are ready to:
- setup Jenkins locally
- push logs to Nexus Akraino Repository
Note: In this guide, we use docker container for Jenkins installation.
Setup Jenkins locally:
Create a local directory on host-machine, where you want to store the container-logs:
Setup Volume for Jenkins container on Host-machinemkdir /jenkins sudo chown -R 1000:1000 /jenkins/
Install/setup Jenkins using the command:
docker run --name JENKINS-CONTAINER-NAME --rm --detach --privileged --network jenkins --network-alias docker --volume /jenkins:/var/jenkins_home --publish 2376:2376 -p 80:8080 -p 50000:50000 mehmoodasif/jenkins
Setup credentials to access Nexus Akraino Repository:
Create an a .netrc file as follows:
.netrc filemachine nexus.akraino.org login LFID_USERID password LFID_PASSWORD
- Copy the .netrc file to /jenkins/ directory of host-machine.
Push logs to Nexus Akraino Repository:
To push the logs using, you'll have to:
- write a script to push logs
- create/configure a job on your jenkins
- validate that the CICD logs on Nexus Akraino Repository
Write a script to push logs:
Create an .sh file. We named it as push-logs.sh:
NEXUS_URL=https://nexus.akraino.org SILO=<silo name provided above> JENKINS_HOSTNAME=<hostname/IP of your Jenkins host> # JOB_NAME and BUILD_NUMBER should be set by Jenkins BUILD_URL="${JENKINS_HOSTNAME}/job/${JOB_NAME}/${BUILD_NUMBER}/" NEXUS_PATH="${SILO}/job/${JOB_NAME}/${BUILD_NUMBER}" lftools deploy logs $NEXUS_URL $NEXUS_PATH $BUILD_URL echo "Logs uploaded to $NEXUS_URL/content/sites/logs/$NEXUS_PATH"
Create/configure a job on your Jenkins:
Follow these steps:
- Log into to Jenkins
- Through the Dashboard, go to New Item
- (in our case, we used push-logs)
- Select the Pipeline options shown
- Click OK
In the General (tab), under the Pipeline section, Pipeline script option must be selected. And paste the below provided groovy script into the Script area. The script is as follows:
Below line change-directory to where your script exists.An example (groovy-script) to push logs to Nexus Akraino Repositorypipeline { agent none stages { stage ("push-logs-nexus") { agent any steps { sh "echo 'Start of job (push-logs)'" sh "pwd" dir("../scripts/") { sh "pwd" sh "./push-logs.sh" } sh "pwd" sh "echo 'End of job (push-logs)'" } } } }
- Now you have to configure the job to load/run the script to push logs (wrote in the previous step). An example on how to is provided below:
Validate that the CICD logs on Nexus Akraino Repository:
Visit the associated repository to your blueprint. The logs must be there. In our case, the link is:
- https://nexus.akraino.org/content/sites/logs/jejunu-pred-vanet-mec/job/push-logs, in which:
- jejunu-pred-vanet-mec is your blueprint's nexus repository
- push-logs is your job name created on Jenkins