-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparameters-triggers.groovy
51 lines (46 loc) · 1.48 KB
/
parameters-triggers.groovy
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
// Below is a Jenkinsfile that demonstrates how to pass parameters and set up triggers. This example will include:
// Parameters for the pipeline.
// A build trigger based on a schedule.
pipeline {
agent any
// Define parameters
parameters {
string(name: 'BRANCH_NAME', defaultValue: 'main', description: 'Branch to build')
booleanParam(name: 'DEPLOY_TO_PRODUCTION', defaultValue: false, description: 'Deploy to production?')
}
// Define triggers
triggers {
// Cron trigger to schedule the job every day at midnight
cron('H H * * *')
}
stages {
stage('Checkout') {
steps {
// Checkout the code from the specified branch
checkout([$class: 'GitSCM', branches: [[name: "${params.BRANCH_NAME}"]],
userRemoteConfigs: [[url: 'https://github.com/your-repo/your-project.git']]])
}
}
stage('Build') {
steps {
echo 'Building...'
// Your build commands here
}
}
stage('Test') {
steps {
echo 'Testing...'
// Your test commands here
}
}
stage('Deploy') {
when {
expression { return params.DEPLOY_TO_PRODUCTION }
}
steps {
echo 'Deploying to production...'
// Your deployment commands here
}
}
}
}