Vinu Pillai
Vinu Pillai

Reputation: 127

Trigger a specific build in jenkins pipeline

I have a pipeline which contains stages of build - test - performance test - deploy.

I want to run the performance test stage only wednesday night in the pipeline because it takes lot of time to run and publish the report.

Is this scenario possible to incorporate in jenkinsfile? Please advise.

Thanks in advance.

Upvotes: 0

Views: 256

Answers (1)

Altaf
Altaf

Reputation: 3086

Yes, Please see below code / method which will give you an idea of how to execute specific stage at a specific day or at a specific condition.You can change the conditions based on your requirement.

# Get the day from the build timestamp
def getday = env.BUILD_TIMESTAMP
getday = getday .split(" ")
// Extract current day
getday = getday [3]
pipeline 
{
  agent any

stages {
 stage('Build') {
        steps {
            script {
                  // do something
                )
            }
        }
    }
stage('Performance test') {
      when 
            {
                // Note: You can change condition as per your need
                // Stage will run only when the day is Wed
                expression {
                     getday == "Wed"
                }
            }
        steps {
            script {
                  // do something
                )
            }
        }
    }
}

Configure BuildTimestamp: If your build time stamp is not configured to get day information, then you can do it using below method
https://plugins.jenkins.io/build-timestamp/
Manage Jenkins -> Configure System -> Build Timestamp -> Click on Enable BUILD_TIMESTAMP. Put Pattern as :yyyy-MM-dd HH:mm:ss z EEE

Upvotes: 1

Related Questions