Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide merge request labels as environment variables #901

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anton-johansson
Copy link
Contributor

@anton-johansson anton-johansson commented Feb 28, 2019

Closes #900
Also see #646

Example pipeline:

pipeline {
    agent any
    triggers {
        gitlab(
            triggerOnPush: true,
            triggerOnMergeRequest: true,
            triggerOpenMergeRequestOnPush: "source",
            triggerOnNoteRequest: true,
            branchFilterType: "All",
            skipWorkInProgressMergeRequest: false)
    }
    stages {
        stage('Prepare') {
            steps {
                echo sh(returnStdout: true, script: 'env')
            }
        }
    }
}

Output:

[Pipeline] sh
+ env
[Pipeline] echo
gitlabMergeRequestTargetProjectId=1
gitlabSourceRepoURL=ssh://git@localhost:10022/root/anton.git
JENKINS_HOME=/var/jenkins_home
gitlabTargetRepoHttpUrl=http://localhost:10080/root/anton.git
JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental
gitlabMergedByUser=root
RUN_CHANGES_DISPLAY_URL=http://localhost:8080/job/anton/5/display/redirect?page=changes
HOSTNAME=4ea3e1ce3cbc
gitlabTargetRepoSshUrl=ssh://git@localhost:10022/root/anton.git
SHLVL=0
NODE_LABELS=master
HUDSON_URL=http://localhost:8080/
HOME=/var/jenkins_home
BUILD_URL=http://localhost:8080/job/anton/5/
HUDSON_COOKIE=85dd3aca-ba51-4ed6-91ce-ffad4cb29895
gitlabTargetBranch=master
JENKINS_SERVER_COOKIE=durable-6b17982e7e0d911a16d9ced57c7aafff
gitlabMergeRequestIid=1
JENKINS_UC=https://updates.jenkins.io
gitlabSourceRepoHttpUrl=http://localhost:10080/root/anton.git
gitlabMergeRequestState=opened
WORKSPACE=/var/jenkins_home/workspace/anton
gitlabMergeRequestTitle=Update README.md
JAVA_VERSION=8u151
gitlabMergeRequestLastCommit=d0b6cdced0adb9808a27787b8cc5d58459170840
NODE_NAME=master
gitlabSourceRepoSshUrl=ssh://git@localhost:10022/root/anton.git
gitlabTargetRepoName=anton
gitlabTargetNamespace=root
gitlabMergeRequestLabels=deploy,bug
STAGE_NAME=Prepare
CA_CERTIFICATES_JAVA_VERSION=20170531+nmu1
gitlabSourceRepoHomepage=http://localhost:10080/root/anton
EXECUTOR_NUMBER=0
gitlabBranch=test
BUILD_DISPLAY_NAME=#5
gitlabSourceBranch=test
gitlabUserEmail=admin@example.com
JENKINS_VERSION=2.89.4
HUDSON_HOME=/var/jenkins_home
JAVA_DEBIAN_VERSION=8u151-b12-1~deb9u1
JOB_BASE_NAME=anton
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
BUILD_ID=5
BUILD_TAG=jenkins-anton-5
gitlabMergeRequestId=1
gitlabActionType=MERGE
JENKINS_URL=http://localhost:8080/
LANG=C.UTF-8
JOB_URL=http://localhost:8080/job/anton/
gitlabSourceRepoName=anton
gitlabSourceNamespace=root
BUILD_NUMBER=5
JENKINS_NODE_COOKIE=63f85221-303e-4906-aca5-59985eb83c63
RUN_DISPLAY_URL=http://localhost:8080/job/anton/5/display/redirect
JENKINS_SLAVE_AGENT_PORT=50000
HUDSON_SERVER_COOKIE=e3dff077c89c3538
JOB_DISPLAY_URL=http://localhost:8080/job/anton/display/redirect
JOB_NAME=anton
COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log
PWD=/var/jenkins_home/workspace/anton
JAVA_HOME=/docker-java-home
gitlabUserName=Administrator

Limitations:

  • Does not work when commenting on the MR, because that GitLab webhook does not include merge request labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant