User Tools
Writing /app/www/public/data/meta/toolsandtechnologies/jenkins_2.meta failed
toolsandtechnologies:jenkins_2
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| toolsandtechnologies:jenkins_2 [2019/01/29 17:37] – General Troubleshooting Section Added - Stuck Builds ashevyakov | toolsandtechnologies:jenkins_2 [2023/06/07 17:39] (current) – [Artifactory storage] - fix url redirect aryan | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Jenkins 2 ====== | ||
| + | ===== Introduction ===== | ||
| + | |||
| + | Jenkins 2 can be accessed at: [[https:// | ||
| + | |||
| + | It is encouraged to create new projects using the Pipeline plugin of Jenkins 2 and with Jenkinsfile being part of the project SCM. | ||
| + | It is suggested to get yourself familiar with the Pipeline plugin (e.g. using this [[https:// | ||
| + | There are also some best practises to be followed as described [[https:// | ||
| + | |||
| + | The main benefits of using Jenkins Pipelines: | ||
| + | * The complete definition of Jenkins build is part of SCM (as Jenkinsfile) | ||
| + | * Jenkinsfile is versioned and reflects particular branches | ||
| + | * It allows splitting the build into several stages, which allows pipelining (once a stage is finished, later build can perform that stage) | ||
| + | |||
| + | ===== Integration to BitBucket ===== | ||
| + | |||
| + | The installed Jenkins has prepared credentials for accessing the BitBucket repositories. | ||
| + | |||
| + | The credentials have ' | ||
| + | |||
| + | To create password for Jenkins (or other application) go to https:// | ||
| + | |||
| + | {{: | ||
| + | |||
| + | It is crucial to add at least read/write access to repositories in order to make cloning and tagging work. | ||
| + | |||
| + | **errigal_robot** account should be used for all builds, and NOT personal accounts due to the issue of account closure in Bitbucket directly affecting the build process | ||
| + | |||
| + | Example below shows how to use these credentials in order to clone a repo and tag it with a build number. | ||
| + | |||
| + | ===== Sample Pipeline ===== | ||
| + | Following code represents very early and basic Pipeline of the Fiber project (http:// | ||
| + | <code groovy> | ||
| + | #!groovy | ||
| + | // Define versioning | ||
| + | versionNumber = " | ||
| + | currentBuild.displayName = versionNumber | ||
| + | // ID of the Jenkins credentials for interaction with BitBucket | ||
| + | bitbucketCredentialsId = ' | ||
| + | // The hostname/ | ||
| + | repoLocation = ' | ||
| + | |||
| + | node() { | ||
| + | stage " | ||
| + | // Checkout the GIT using provided URL and credentials | ||
| + | git credentialsId: | ||
| + | |||
| + | stage " | ||
| + | // Run the Gradle wrapper to clean, build and test the code | ||
| + | sh " | ||
| + | // Archive test result so they are browsable from Jenkins | ||
| + | step([$class: | ||
| + | |||
| + | stage "Tag build in Git" | ||
| + | // Use credentials to create versionNumber tag on current commit and push it back to BitBucket | ||
| + | withCredentials([[$class: | ||
| + | sh(" | ||
| + | sh(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The resulting Jenkins job looks following: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== How to Install on Ubuntu ===== | ||
| + | * Ensure java 8 or later is the defaulf java of the system, if not install it - note it will run with java 7, not java 6 but SonarQube needs Java 8 | ||
| + | * java -version | ||
| + | * install Jenkins | ||
| + | * wget -q -O - https:// | ||
| + | * sudo sh -c 'echo deb http:// | ||
| + | * sudo apt-get update | ||
| + | * sudo apt-get install jenkins | ||
| + | |||
| + | ===== Enabling Email Notification ===== | ||
| + | * Go to Jenkins, Manager Jenins, Configure System | ||
| + | * Go to System Admin e-mail address and make it - SERVER/ | ||
| + | * Go to E-mail Notification, | ||
| + | * Make it look like : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | ===== Extra Plugins ===== | ||
| + | On top of the default Jenkins load, the following plugins need to be installed | ||
| + | * Ansible plugin | ||
| + | * AntExec | ||
| + | * Bitbucket OAuth Plugin | ||
| + | * Bitbucket Plugin | ||
| + | * Hudson SCP publisher plugin | ||
| + | * JaCoCo plugin | ||
| + | * SonarQube Scanner for Jenkins | ||
| + | * JIRA Plugin | ||
| + | * Discard Old Build | ||
| + | * Build Keeper Plugin | ||
| + | * Database Plugin | ||
| + | * Database MySQL plugin | ||
| + | * Pipeline Utility Plugin | ||
| + | * Copy Artifact Plugin | ||
| + | * Run Selector Plugin | ||
| + | * Slack Notification Plugin | ||
| + | * ThinBackup plugin | ||
| + | * Parameterized Scheduler | ||
| + | * Gatling Plugin | ||
| + | |||
| + | |||
| + | ===== Setting up SonarQube ===== | ||
| + | |||
| + | Go to Manage Jenkins, Configure System and make SonarQube servers look like : | ||
| + | {{ : | ||
| + | |||
| + | ===== Automatic build artefacts discarding and keeping important builds ===== | ||
| + | Following snippet (using Declarative Jenkins Pipeline) shows how to setup automatic build discarding (this one is setup to keep only last 20 builds) - Discard Old Build plugin is needed for this. In case the build is important and you want to keep it, there is a button in each build (blue, on the right side), which allows keeping that build regardless of the discarding plugin - this needs the Build Keeper plugin to be installed. | ||
| + | |||
| + | <code groovy> | ||
| + | pipeline { | ||
| + | agent any | ||
| + | options { | ||
| + | // Skip the default SCM Checkout Stage - we are doing our own checkout | ||
| + | skipDefaultCheckout(true) | ||
| + | // Keep build artifacts and logs only for last 20 builds | ||
| + | buildDiscarder(logRotator(numToKeepStr:' | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Artifactory storage ===== | ||
| + | |||
| + | Artifactory configuration is covered [[development: | ||
| + | |||
| + | Each pipeline has a step to push the build suite (war/jar, pom, XML etc) to the artifactory store in [[http:// | ||
| + | |||
| + | Ideally (as of June 6th, 2023 not working) we should keep | ||
| + | |||
| + | *- 15 days of IDMS & AUTO | ||
| + | *- 30 days of SUPPORT | ||
| + | *- Last 4 REL- | ||
| + | |||
| + | Deployment is covered via | ||
| + | < | ||
| + | stage (' | ||
| + | steps { | ||
| + | nexusPublisher( | ||
| + | nexusInstanceId: | ||
| + | nexusRepositoryId: | ||
| + | packages: [ | ||
| + | [$class: ' | ||
| + | | ||
| + | | ||
| + | ], | ||
| + | | ||
| + | ] | ||
| + | ] | ||
| + | ) | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The deployment playbooks should then source the artefact from the repo and not from our dev jenkins with a public IP interface (security risk). | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== Generating API token (e.g. for Ansible) ===== | ||
| + | The tokens used in API (e.g. in ansible role artefact-deployment) are generated per Jenkins user so you have to navigate to the currently logged in user (usually top right corner of the Jenkins page). Or alternatively you can go to URL like http:// | ||
| + | There is a section **API Token**, which allows you to view/create tokens. This token then needs to be used in the API (check the role artefact-deployment in deployment-playbooks for an example, the token goes to default/ | ||
| + | |||
| + | ===== General Troubleshooting ===== | ||
| + | ==== Immediately stopping a stuck build ==== | ||
| + | " | ||
| + | |||
| + | Script (adjust values accordingly): | ||
| + | <code groovy> | ||
| + | Jenkins.instance.getView(' | ||
| + | if (it.toString() == ' | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | </ | ||