Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
News ticker list
displayTime5000
color#46A7DE
width100%
titleOther powerful plugins from Mohami

Version 4.2 of Webhook to Jenkins for Bitbucket version 4.2 and onwards higher support sending custom URL parameters to Jenkins during the notification/trigger process. But this will not work unless Jenkins has been configured to allow url parametersTo use this feature, you must also configure Jenkins to allow URL parameters.

Info

The URL parameter feature is only available when using the Git plugin. Bitbucket Branch Source plugin is not supported at this time.

Table of Contents

Setup

Configuring Jenkins

Git Plugin for Jenkins version 2.5.0 and onwards higher will by default reject all url URL parameters. You must configure Jenkins to allow URL parameters by doing ONE of the following:

  • Setting the Jenkins JVM switches -Dhudson.model.ParametersAction.keepUndefinedParameters=true and -Dhudson.plugins.git.GitStatus.allowNotifyCommitParameters=true.

...

  •  This allows arbitrary notify commit parameters (reference). Only enable this if you trust all unauthenticated users not to

...

  • pass harmful arguments to your jobs.

  • Setting the Jenkins JVM switch -Dhudson.plugins.git.GitStatus.safeParameters=PARM1,PARM1.

...

  •  If this property is set to a comma-separated list of parameters,

...

  • those parameters

...

  • are allowed for any job. Only set this value for parameters you trust in all the jobs in your system.

For detailed instructions on adding Java arguments to Jenkins, see the CloudBees guidehere

Usage

Configure Bitbucket Server

  1. Go Log in to your hook settings, then go to Webhook to Bitbucket for Jenkins → Advanced Configuration → URL Parameters → ParametersBitbucket repository and navigate to Repository Settings > Hooks > Enable or click the Edit setting for Webhooks to Jenkins Server icon.

  2. Click the  Advanced Configuration taband locate URL Parameters at the bottom of the dialog.

  3. Enter the URL parameter into the parameter boxfield. The rules for the parameters are as follows:

    • The formatting for the

    url
    • URL parameter is DESIRED_VARIABLE_NAME={PARAMETER_NAME}

    • Every parameter

    must start
    • starts on a new line.

    Name
    • The name given to your parameter

    whatever you'd like, this
    • is how you

    're going to
    • reference the parameter in Jenkins. In our example

    we're going to name
    • the parameter

    e.g. TARGET
    • name is TARGET_BRANCH.

    • To pull information from Bitbucket to use as a parameter (like the branch name),

    look at the table below and put it
    • refer to the Available parameters section and enter the parameter on the right side of the equal sign

    and surround it
    • surrounded with curly braces

    , e.g. 
    • {BRANCH_NAME}

    If you want to put
    • .

    • To use your own custom value,

    just
    • eliminate the curly braces and

    put
    • enter the value

    at
    • to the right

    side
    • of the equal sign.

...

Note

Please note, that you You cannot use additional parameters together with Omit SHA1 Hash Code option enabled with Git endpoint - this . This case is not supported on the Jenkins side, see details here.

Configure Jenkins

To be able to access the parameter in your Jenkins job do the following:

  1. Go to your project configuration, then job, click Configure from the left sidebar and go to the General tab. Select This project is parameterized.Put

  2. click Add Parameter and select String Parameter

  3. in the Name field, enter the name of the parameter that you chose above (URL Parameter settings in the webhook) in the name boxused in the Webhook to Jenkins URL Parameters field.

  4. For each additional parameter, click Add Parameter, select String Parameter and enter the name of the next parameter.

  5. Click Save.

You should now have your parameters passed to Jenkins.

...

Available Parameters

Here's a list of available parameters:To pull information from Bitbucket to use as a parameter (like the branch name), refer to the table below and put the parameter on the right side of the equal sign and surround it with curly braces.

For example, TARGET_BRANCH={PR_DESTINATION}, where PR_DESTINATION is the branch name of the destination branch.

Parameter

Description

PR_SOURCE 

The branch name of the source branch (Only available in pull requests).

PR_DESTINATION 

The branch name of the destination branch (Only available in pull requests).

PR_SOURCE_COMMIT

The most recent commit id/reference for the source branch (Only available in pull requests).

PR_DESTINATION_COMMIT

The most recent commit id/reference for the destination branch (Only available in pull requests).

PR_ID

The pull request ID number (Only available in pull requests).

PR_URL

The URL of the pull request (Only available in pull requests).

PR_TITLE

The title of the pull request (Only available in pull requests).

PR_ACTION

The action that triggered build for the pull request (Only available in pull requests).

PR_VERSION

The version of the pull request (Only available in pull requests).

PR_REVIEWERS

The pull request reviewer display names (Only available in pull requests).

PR_REVIEWERS_SLUG

The pull request reviewer slugs (Only available in pull requests).

REPOSITORY

The repository being affected by the event.

PROJECT

The project the repository being affected by the event is located in.

BRANCH

The branch associated with the event.

COMMIT

The commit id/reference associated with the event.

USER

The username of the user who initiated the event.

USER_EMAIL

The email of the user who initiated the event.

BB_URL

The base URL of the Bitbucket instance hosting the affected repository.

BB_PORT

The network port of the Bitbucket instance hosting the affected repository.

...