These templates are imported as a DSL job in Jenkins and then new jobs are created from these templates.
- Jenkins Jobs
- TOC
- Jenkins Job DSL API
- Summary
- Updating Credentials
- Plugins
- Active Choices (Official Site)
- AnsiColor (Official Site)
- Authorize Project (https://plugins.jenkins.io/authorize-project)
- CloudBees Docker Build and Publish (Official Site)
- Docker Plugin (Official Site)
- Email Extension (Official Site)
- Environment Injector (EnvInject) (Official Site)
- Extra Columns (Official Site)
- Git Parameter (Official Site)
- InfluxDB (Official Site)
- JaCoCo (Official Site)
- Jenkins user build vars (Official Site)
- Job Configuration History (Official Site)
- Job DSL (Official Site)
- JUnit (Official Site)
- Locale (Official Site)
- MSBuild (Official Site)
- MSTest (Official Site)
- MSTestRunner (Official Site)
- Test Results Analyzer (Official Site)
- Parameterized Scheduler plugin (Official Site)
- Pipeline Utility Steps(Official Site)
- PostBuildScript (Official Site)
- PowerShell (Official Site)
- Prometheus metrics (Official Site)
- Warnings Next Generation (Official Site)
- Sidebar Link (Official Site)
- Simple Theme (Official Site)
- Slack Notification (Official Site)
- SonarQube Scanner (Official Site)
- /userContent in Git (Official Site)
- xUnit (Official Site)
- Jenkins useful folder paths
- Using docker as a build executor
- Enable Windows PSRemoting
- Delete Jenkins workspace @tmp files using crontab and scheduler
- Custom scripts:
- Linux (Python) - Cloning docker images from one repo to another
- Linux (bash) - Change file encoding from CRLF to LF
- Linux (bash) - Change file encoding from CRLF to LF (path is passed as argument)
- Linux (bash) - Change file encoding from CRLF to LF with prompt (path is passed as argument)
- Linux (bash) - Display all characters between 'Version' and ']' characters
- Windows (Powershell) - Display version number from a file
- Linux (bash) - Date format
- Windows (Powershell) - Date format
- Additional links:
The job-dsl-plugin allows the programmatic creation of projects using a DSL. Pushing job creation into a script allows you to automate and standardize your Jenkins installation, unlike anything possible before.
Jenkins is a wonderful system for managing builds, and people love using its UI to configure jobs. Unfortunately, as the number of jobs grows, maintaining them becomes tedious, and the paradigm of using a UI falls apart. Additionally, the common pattern in this situation is to copy jobs to create new ones, these "children" have a habit of diverging from their original "template" and consequently it becomes difficult to maintain consistency between these jobs.
The Jenkins job-dsl-plugin attempts to solve this problem by allowing jobs to be defined with the absolute minimum necessary in a programmatic form, with the help of templates that are synced with the generated jobs. The goal is for your project to be able to define all the jobs they want to be related to their project, declaring their intent for the jobs, leaving the common stuff up to a template that were defined earlier or hidden behind the DSL.
More info at: Jenkins Job DSL API and Job DSL Plugin.
In some cases we will find yourcredentials inside our Groovy files. These credentials need to be updated with a new ones. For that we will go to Jenkins.
- Go to credentials
- Click Jenkins (under 'Stores scoped to Jenkins')
- Click Global credentials (unrestricted) (under 'System')
- On the left side click on Add Credentials
Once our credentials are created a new ID will be generated. This ID should be replaced on yourcredentials.
Active Choices (Official Site)
The Active Choices plugin allows the creation of dynamic and interactive parameters for freestyle Jenkins jobs. Active Choice parameters can be dynamically updated and can be rendered as combo-boxes, check-boxes, radio-buttons or rich HTML.
AnsiColor (Official Site)
This plugin adds support for ANSI escape sequences, including color, to Console Output
Authorize Project (https://plugins.jenkins.io/authorize-project)
Configure projects to run with specified authorization.
CloudBees Docker Build and Publish (Official Site)
This plugin provides the ability to build projects with a Dockerfile, and publish the resultant tagged image (repo) to the docker registry.
Docker Plugin (Official Site)
This plugin allows slaves to be dynamically provisioned using Docker.
Email Extension (Official Site)
This plugin allows you to configure every aspect of email notifications. You can customize when an email is sent, who should receive it, and what the email says.
Environment Injector (EnvInject) (Official Site)
EnvInject plugin provides the following features:
-
Removes inherited environment variables by the Jenkins Java process
-
Injects environment variables at node (master/slave) startup
-
Executes a setup script before or/and after a SCM checkout for a run
-
Injects environment variables before or/and after a SCM checkout for a run
-
Injects environment variables as a build step for a run
-
Injects password values for a run
-
Exports environment variables at the end of the build in order to to know the set of environment variables used for each build
Extra Columns (Official Site)
This plugin is supposed to group multiple extra columns in one convenient plug-in. Maybe other simple column plug-ins can be merged into this one in the future.
Git Parameter (Official Site)
Adds ability to choose branches, tags or revisions from git repository configured in project.
InfluxDB (Official Site)
Sends Jenkins build metrics into InfluxDB.
JaCoCo (Official Site)
This plugin allows you to capture code coverage report from JaCoCo. Jenkins will generate the trend report of coverage and some other statistics. It also includes functionality to include columns in Dashboards which displays the latest overall coverage numbers and links to the coverage report.
Jenkins user build vars (Official Site)
This plugin provides a set of environment variables that describe the user who started the build.
Job Configuration History (Official Site)
Saves copies of all job and system configurations.
Job DSL (Official Site)
The job-dsl-plugin allows the programmatic creation of projects using a DSL. Pushing job creation into a script allows you to automate and standardize your Jenkins installation, unlike anything possible before.
JUnit (Official Site)
Allows JUnit-format test results to be published.
Locale (Official Site)
This plugin controls the language of JenkinsNormally, Jenkins honors the browser's language preference if a translation is available for the preferred language, and uses the system default locale for messages during a build.
MSBuild (Official Site)
This plugin allows you to use MSBuild to build .NET projects.
MSTest (Official Site)
This plugin converts MSTest TRX test reports into JUnit XML reports so it can be integrated with Jenkin's JUnit features. This plugin converts the .coveragexml files found in the project workspace to the EMMA format.
MSTestRunner (Official Site)
This plugin allow you to execute test using MSTest command line tool.
Furter information: https://www.automatetheplanet.com/configure-jenkins-mstest-execution/
Test Results Analyzer (Official Site)
A plugin that shows history of test execution results in a tabular format.
Parameterized Scheduler plugin (Official Site)
This plugin is for configuring a cron style timer schedule for parameterized builds.
Further information:
Pipeline Utility Steps(Official Site)
Small, miscellaneous, cross platform utility steps for Pipeline Plugin jobs
PostBuildScript (Official Site)
This plugin allows you to run the following actions after a build:
- Batch or shell scripts
- Groovy scripts
- Build steps
You can configure these actions depending on the build status (i.e., only run when build is successful). Scripts can also be executed on the master, on slaves or both. On matrix projects, the build can be executed on each axis.
Please refer to the plugin description for further information.
PowerShell (Official Site)
Provides Jenkins integration with Windows PowerShell
Prometheus metrics (Official Site)
Exposes a Prometheus metrics endpoint.
Warnings Next Generation (Official Site)
This plugin collects compiler warnings or issues reported by static analysis tools and visualizes the results. Jenkins' Warnings Next Generation Plugin collects compiler warnings or issues reported by static analysis tools and visualizes the results. It has built-in support for almost hundred static analysis tools (including several compilers), see the list of supported report formats. It replaces the Jenkins Static Analysis Suite that has been part of the Jenkins plugin eco-system for more than ten years now. I.e. it makes the following Jenkins plugins obsolete: Android Lint, CheckStyle, Dry, FindBugs, PMD, Warnings, Static Analysis Utilities, Static Analysis Collector Plugins, Task Scanner, etc.
Sidebar Link (Official Site)
Add links in the sidebar of the Jenkins main page, view tabs and project pages.This simple plugin adds an Additional Sidebar Links section in the main Jenkins configuration page, with settings for link URLs, texts and icons. These links will be shown in the top-level Jenkins pages (main page, user list, build history, My Projects and other project view tabs). Sidebar links for particular jobs may also be added in the job configuration pages.
Simple Theme (Official Site)
This plugin allows to customize Jenkin's appearance with custom CSS and JavaScript. It also allows to replace the Favicon.
Add the following under -> Jenkins > Configure System > Theme
- https://cdn.rawgit.com/afonsof/jenkins-material-theme/gh-pages/dist/material-cyan.css
- https://tobix.github.io/jenkins-neo2-theme/dist/neo-light.css
More info here.
Slack Notification (Official Site)
Provides Jenkins notification integration with Slack or Slack compatible applications like RocketChat and Mattermost.
SonarQube Scanner (Official Site)
This plugin allow easy integration of SonarQube™, the open source platform for Continuous Inspection of code quality.
/userContent in Git (Official Site)
Jenkins has a mechanism known as "User Content", where administrators can place files inside $JENKINS_HOME/userContent, and these files are served from http://yourhost/jenkins/userContent. This can be thought of as a mini HTTP server to serve images, stylesheets, and other static resources that you can use from various description fields inside Jenkins.
This plugin exposes this this $JENKINS_HOME/userContent directory as a Git repository, allowing administrators to use git to push/pull changes and manage them with history.
Once this plugin is installed, see http://yourserver/jenkins/userContent.git in your browser for how to access this repository.
xUnit (Official Site)
This plugin makes it possible to publish the test results of an execution of a testing tool in Jenkins.
definition | description | path |
---|---|---|
jenkins_home | jenkins default installation path | /var/lib/jenkins |
jobs | place where builds status are stored | $jenkins_home/jobs |
userContent | place to store static files and serve them as a url | $jenkins_home/userContent |
workspace | place where projects are cloned | $jenkins_home/workspace |
plugins | place where plugins are installed | $jenkins_home/plugins |
jenkins.war | place where jenkins.war file is located as a service ($> whereis jenkins ) | /usr/share/jenkins |
jenkins | In order to pass Java arguments to Jenkins you need to change the Jenkins service configuration file | /etc/default/jenkins |
jenkins.log | log file of jenkins | /var/log/jenkins |
- Install Docker Plugin.
- Configure Jenkins to work with docker: Manage Jenkins > Configure system > Cloud > docker like the image below.
- Now that you have the slave configurations ready, you can create a job, select “Restrict where this project can be run” option and select the docker host as slave using the label as shown below. "docker_slave_agent.jpg")
Enable-PSRemoting -Force
winrm set winrm/config/service/Auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}'
To edit or create your own crontab file (for specific user), type the following command at the UNIX / Linux shell prompt:
$> crontab -e
Then type in the file:
# Delete Jenkins @tmp folders in /var/lib/jenkins/workspace. From mon-fri at 09:00
0 9 * * 1-5 rm -rf /var/lib/jenkins/workspace/*@tmp
After saving a new file (username) will be created in: /var/spool/cron/crontabs/
To check if the cron has been run we perform the following command:
$> tailf -n 100 /var/log/syslog | grep CRON
Open "Task Scheduler" and add the "delete_jenkins" task.
We will start Powershell program with arguments:
Program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments: Remove-Item -Path C:\Jenkins\workspace\* -Filter *@tmp
We add the desired trigger, for example everyday at 09:00 am.
# This progam clones docker images from one repo (harbor) to another (azure container registry)
import datetime
import time
import docker
fromrepo = ('<user>', '<password>', '<origin_repo>')
fromrepoproject = '/cloudmaster'
torepo = ('<user>', '<password>', '<destination_repo>')
images = {'/jenkins':'1.1.0',
'/nginx':'2.0.0'
}
client = docker.from_env()
start = datetime.datetime.now()
start_time = time.time()
for repo in fromrepo,torepo:
client.login(username=repo[0], password=repo[1], registry=repo[2])
print('Login in -> '+ repo[2] + ' <- succeeded!')
for image,tag in sorted(images.items()):
origin = fromrepo[2]+fromrepoproject+image+':'+tag
destination = torepo[2]+image+':'+tag
print('Pulling the following image: ' + origin)
client.images.pull(origin)
print('Tagging the following image: ' + origin)
client.images.get(origin).tag(torepo[2]+image, tag)
print('Pushing the following image: ' + destination)
client.images.push(torepo[2]+image, tag)
print('Removing generated images: ' + origin + ' and ' + destination )
client.images.remove(origin, True)
client.images.remove(destination, True)
client.images.list()
finish = datetime.datetime.now()
print("The process started at: " + start.strftime("%Y/%m/%d %H:%M:%S") + " and finished at: " + finish.strftime("%Y/%m/%d %H:%M:%S"))
print("The execution took: %s seconds." % (time.time() - start_time))
#!/bin/bash
# This script changes the line enconding to Linux LF
for file in $(find $directory -type f -name "*.sls")
do
dos2unix $file
done
#!/bin/bash
displayError()
{
echo "Error!"
echo "Usage: $0 <path>"
exit 1
}
if (($# < 1)); then
displayError
fi
# This script changes the line enconding to Linux LF
for file in $(find $1 -type f -name "*.sls")
do
dos2unix $file
done
#!/bin/bash
# This script changes the line enconding to Linux LF
displayError()
{
echo "Error!"
echo "Usage: $0 <path>"
exit 1
}
if (($# < 1)); then
displayError
fi
echo "The following files will be changed:"
echo "------------------------------------"
for file in $(find $1 -type f -name "*.sls")
do
ls $file
done
echo "------------------------------------"
read -r -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
for file in $(find $1 -type f -name "*.sls")
do
dos2unix $file
done
else
echo "Aborted"
fi
version=$(sed -n '1p' changelog.txt | sed 's/.*Version \(.*\)].*/\1/')
# ------------------------------- #
Example:
changelog.txt
[Version 1.0.0] 2018/01/01
Output: 1.0.0
# --- Getting service version --- #
$file = "$env:WORKSPACE/changelog.txt"
$version=Get-Content $file -TotalCount 1
$version -Match '(?s)\[.*?]+' | Out-Null
$version1 = $Matches.Values
$version2=$version1.Remove(0,9)
$finalversion=$version2 -replace ".{1}$"
echo $finalversion
# ------------------------------- #
Example:
changelog.txt
[Version 1.0.0]
Output: 1.0.0
echo Date: $(date +"%Y/%m/%d at %T")
Get-Date -UFormat "%Y/%m/%d at %H:%M:%S"
- Install Powershell 5 in Windows Server 2008 R2
- Download WMF 5.0 (Win8.1AndW2K12R2-KB3134758-x64.msu)
- Script is not digitally signed
- How to copy a local file to remote machines
- Create a PSCredential object
- Creating a PS Credential from a Clear Text Password in Powershell
- Working with Passwords, Secure Strings and Credentials in Windows PowerShell
- How to copy files to and from Nano Server
- The WinRM client cannot process the request. If the authentication scheme is different
- Powershell version 5 Copy-Item -FromSession cannot be found
- Error with PowerShell command for copying file to remote server with credential
- Bug: Copy-Item -FromSession Fails if Local Machine Doesn't Have the Drive Being Copied From
- Ejecutar comandos remotos
- Use PowerShell Invoke-Command to run scripts on remote computers
- Using the Remove-Item Cmdlet
- Using the Stop-Service Cmdlet
- SparseCheckoutpaths
- Crontab generator
- Installing Hyper-V on WindowsServer on VMWware (Hyper-V cannot be installed. A hypervisor is already running)
- Install OpenSSH
- How to Enable Support for Nested 64bit & Hyper-V VMs in vSphere 5
- Nested ESXi Enhancements in vSphere 6.5
- Error 1067- on start OpenSSH by net start opensshd in windows cmd - ESTA OPCION ME FUNCIONA (hago ssh por cmd)
- stop and delete docker container if its running without errors
- Configure Jenkins MSTest Tests Execution
- How do I display all the characters between two specific strings?
- How-to-pass-variables-from-jenkinsfile-to-shell-command
- Using Email-ext plugin in Jenkins pipeline
- Github - email-ext-plugin templates
- Publish pretty cucumber reports on Jenkins
- Pattern to get string between two specific words/characters using grep [duplicate]
- Where is the cron / crontab log?
- Verify if crontab works
- How to redirect output to a file from within cron?
- how to run cron jobs as a specific user other than root in linux
- Gray filled box icon - default 24x24
- Error: Error applying plan: 1 error(s) occurred: * vsphere_virtual_machine.vm_3: cannot locate virtual machine or template with UUID "423908f8-54b3-432c-5f2b-ff6b8aee5a32": ServerFaultCode: The session is not authenticated
- How do I display all the characters between two specific strings?
- Jenkins Pipeline
- How to check if a string contains a substring in Bash
- How to determine if a string is a substring of another in bash?
- contains in bash
- Git asks for username every time I push
- git-credential-store (1) - Linux Man Pages
- How to configure automatic password handling for git commands:
- How to setup Git Credential store in Windows
- How to set current build result in Pipeline?
- Compiling .Net project - NET Framework Developer Pack
- Jenkins Master and Slaves as Docker Containers
- How To Setup Docker Containers As Build Slaves For Jenkins
- Setup Jenkins Master And Build Slaves As Docker Container
- Monitoring Jenkins with Grafana and Prometheus:
- Delivery Pipelines, with Jenkins 2, SonarQube, and Artifactory
- Analyzing with SonarQube Scanner for Jenkins
- Changing Jenkins build number
- Jenkins pipeline plugin: set the build description
- HTML in job descriptions on jenkins
- Useful Groovy String Functions
- Groovy For Loop Examples
- Lists in Groovy
- Online Groovy Compiler
- How to join multiple lines of file names into one with custom delimiter?
- How do I view all available HDD's/partitions?
- Jenkins: no tool named MSBuild found
- Running msbuild on jenkinsfile
- Passing Jenkins environment variable in Powershell script
- Tutorial de Python virtualenv
- winrm : http error 401 although correct credential supplied
- Enable-PSRemoting
- MSBuild github repository
- Microsoft Build Tools 2015
- specify project file of a solution using msbuild
- Jenkins Pipeline syntax
- Jenkins ext-email plugin fails to send email on build success (file size too big)
- Parameterized Scheduler
- SSH login without password
- TFS and Jenkins Integration
- How do I specify the platform for MSBuild?
- Build fails with 'process apparently never started' error
- Instalación de Jenkins con Docker
- Where to set -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=300
- How to add Java arguments to Jenkins?
- default jenkins file example for checking JAVA_ARGS
- durable-task plugin v1.30 and v1.31 - process aparently never started in /var/lib/jenkins/workspace/jobname
- Logging
- byobu - How can I reattach to my byobu/tmux session?
- durabletask v1.33 - process apparently never started in /var/lib/jenkins/workspace/local-cloud-regression-test@tmp/durable-fa896164
- Demo image for Jenkins Configuration-as-Code
- jenkins-shared-library-example
- jenkins-pipeline-shared-lib
- jenkins-library
- jenkins-shared-libraries
- ods-jenkins-shared-library
- How To Build Your Own Jenkins Shared Library