Jenkins
Jenkins
Jenkins
Tools
- in jenkins tools help us to use the commands of the software required
- There are two possible ways of to these:
- Installing a plugin
- Installing the tools directly on that server itself both these methods ensure that the command required by the application is accessible throughout the jenkins
JOBS
Jenkins Freestyle Job
- The most basic job type in Jenkins
- Straightforward to set up and configure -suitable for simple, small-scale projects
- Lack some advanced features provided by newer job types
Note :
- there occurs an error when you try to install nodejs. via the command that is present in the offical website
- the below command has worked perfectly. The reason is still unknown for me
1 2 3
# As root, install Node.js system-wide (example using apt) curl -fsSL https://deb.nodesource.com/setup_18.x | bash - apt-get install -y nodejs
Attaching the docker directory of host to the container to access docker in the container through a volume
1
2
3
4
docker run -p 8080:8080 -p 50000:50000 -d \
> -v jenkins_home:/var/jenkins_home \
> -v /var/run/docker.sock:/var/run/docker.sock --name updates_jenkins \
> jenkins/jenkins:lts
1
curl https://get.docker.com/ > dockerinstall && chmod 777 dockerinstall && ./dockerinstall
docker.sock file is a Unix socket file, used by the Docker daemon to communicate with the Docker client
1
chmod 666 /var/run/docker.sock
JENKINS PIPELINE JOB
- Pipelines are scripted
- script is written in groovy
- groovy is similar to java
- best practice is to have the script in the source code management
Pipeline Syntax
- Requires Fields in jenkins declarative script
- ‘pipeline” must be top-level
- “agent” - where to execute
- “stages” - where the “work” happens
- “stage” and “steps”
Jenkins File Syntax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pipeline {
agent any
environment{
NEW_VERSION = '1.3.0'
}
stages {
stage('Build') {
steps {
echo 'Building...'
// Add your build commands here
}
}
stage('Test') {
when {
expression { return env.BRANCH_NAME == 'main' }
}
steps {
echo 'Testing...'
// Add your test commands here
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
// Add your deployment commands here
}
}
}
post {
always {
echo 'This will always run after the pipeline completes.'
}
success {
echo 'This will run only if the pipeline succeeds.'
}
failure {
echo 'This will run only if the pipeline fails.'
}
}
}
Environment Variables in Jenkins File
1
https://jenkins.bitinfra.in/enn-vars.html
Tools for Pipeline
- For now tools support maven, jdk and gradle
Parameters
1
2
3
4
5
6
7
8
9
parameters {
choice(name: 'ENVIRONMENT', choices: ['development', 'staging', 'production'], description: 'Select the environment to deploy')
string(name: 'BRANCH_NAME', defaultValue: 'main', description: 'Branch to build')
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests after build')
}
This post is licensed under CC BY 4.0 by the author.
