jenkinsci / ghprb-plugin

github pull requests builder plugin for Jenkins
https://plugins.jenkins.io/ghprb/
MIT License
506 stars 612 forks source link

How to trigger only when there is a specific word in the PR title? #803

Open soondl opened 3 years ago

soondl commented 3 years ago

I want to trigger build only when there is a string "[iOS]" in PR title. For example, [iOS] Fix view logic

I found the parameter "skip build phrase" and I wrote it as follows to match the phrase that does not contain "iOS", but it didn't work. image

Is there any other way? Thank you.

wunaidage commented 2 years ago

I don't think REGEX works here. I also want to know how to make this work

rafaelmedeiros1994 commented 2 months ago

I also had the same problem as you. I could not find the right answer, but my solution was the following:

Let all PR trigger a build.

Then, on the pipeline, you simply do the following:

environment {
    PULL_TITLE = "${ghprbPullTitle}"
}
stage('Skip Build') {
    when {
        expression {
            return !(env.PULL_TITLE =~ /\b(DEV|QA|STG|PRD|DEVOPS)\b/)
        }
    }
    steps {
        script {
            echo "PR title does not contain any of the specified words. Skipping the build."
            currentBuild.result = 'ABORTED'
            error("Aborting the build.")
        }
    }
}

If the PR title doesn't have the words I want, then skip the build.

It will show up like this:

Screenshot 2024-09-19 at 12 21 47 PM