jenkinsci / jenkinsci/gitlab-plugin

gitlab envirements are empty

Open
#1,073 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.4k
Forks
615
Avg merge
4h 32m
Merged PRs (30d)
10

Description

# Issue

I spent a lot of time to search why my settings does not work :(

Problem is that i cannot see variables from GitLab

### Context
- **Gitlab plugin version**: 1.5.13
- **Gitlab version**: 11.9.1
- **Jenkins version**: 2.176
- **Job type**: Freestyle

### Logs & Traces

job config:
```


false


https://url




sourceBranch


false


targetBranch


false


gitlabActionType


false






import hudson.model.*
def env = Thread.currentThread()?.executable.parent.builds[0].properties.get('envVars')
def map = [:]

if (env['gitlabSourceBranch'] != null) {
map['sourceBranch'] = env['gitlabSourceBranch']
}
if (env['gitlabActionType'] != null) {
map['gitlabActionType'] = env['gitlabActionType']
}
map['targetBranch'] = env['gitlabTargetBranch']

// Add additional entries for any other parameters you have created

return map
false

false

true
true
true
true



2


origin
+refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
url.git
2dadb002-db11-4a04-ad1c-9ec6aa4cd5e9




origin/${gitlabSourceBranch}


false




origin
${gitlabTargetBranch}
default
FF




true
false
false
false



true
true
false
true
true
true
never
true
Jenkins please retry a build
true
true
true
All




{AQAAABAAAAAQ1/I03EuzsOd4uqeEyu8EvcHoT4/iP4C8oZ946huzO6s=}

false


false


env






SSH:



someName
false






false
false
false
false
false
[, ]+
echo $GIT_BRANCH;
echo ${gitlabSourceBranch};
echo ${sourceBranch};
echo ${targetBranch};
echo "test";
echo ${gitlabActionType};
0
false
false


false
false


false
false
false




```

injectedEnvVars.txt

```
BUILD_CAUSE=MANUALTRIGGER
BUILD_CAUSE_MANUALTRIGGER=true
BUILD_DISPLAY_NAME=#1
BUILD_ID=1
BUILD_NUMBER=1
BUILD_TAG=jenkins-michal-1
BUILD_URL=http://url/job/michal/1/
DERBY_HOME=/usr/lib/jvm/java-8-oracle/db
EXECUTOR_NUMBER=1
HOME=/var/lib/jenkins
HUDSON_HOME=/var/lib/jenkins
HUDSON_SERVER_COOKIE=7b130974337adcb2
HUDSON_URL=http://url/
J2REDIR=/usr/lib/jvm/java-8-oracle/jre
J2SDKDIR=/usr/lib/jvm/java-8-oracle
JAVA_HOME=/usr/lib/jvm/java-8-oracle
JENKINS_HOME=/var/lib/jenkins
JENKINS_SERVER_COOKIE=7b130974337adcb2
JENKINS_URL=http://url/
JOB_BASE_NAME=michal
JOB_NAME=michal
JOB_URL=http://url/job/michal/
LANG=pl_PL.UTF-8
LOGNAME=jenkins
MAIL=/var/mail/jenkins
NODE_LABELS=master
NODE_NAME=master
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
PWD=/var/lib/jenkins
ROOT_BUILD_CAUSE=MANUALTRIGGER
ROOT_BUILD_CAUSE_MANUALTRIGGER=true
RUN_CHANGES_DISPLAY_URL=http://url/job/michal/1/display/redirect?page=changes
RUN_DISPLAY_URL=http://url/job/michal/1/display/redirect
SHELL=/bin/bash
SHLVL=1
USER=jenkins
WORKSPACE=/var/lib/jenkins/workspace/michal
XDG_RUNTIME_DIR=/run/user/106
XDG_SESSION_ID=c1
_=/usr/bin/daemon
gitlabActionType=
sourceBranch=
targetBranch=null
```

job output:

```
Started by user unknown or anonymous
Running as SYSTEM
[EnvInject] - Loading node environment variables.
[EnvInject] - Preparing an environment for the build.
[EnvInject] - Keeping Jenkins system variables.
[EnvInject] - Keeping Jenkins build variables.
[EnvInject] - Evaluating the Groovy script content
[EnvInject] - Injecting contributions.
Building in workspace /var/lib/jenkins/workspace/michal
using credential 2dadb002-db11-4a04-ad1c-9ec6aa4cd5e9
Cloning the remote Git repository
Cloning repository https://url.git
> git init /var/lib/jenkins/workspace/michal # timeout=10
Fetching upstream changes from https://url.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials
> git fetch --tags --progress https://url.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url https://url.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://url.git # timeout=10
Fetching upstream changes from https://url.git
using GIT_ASKPASS to set credentials
> git fetch --tags --progress https://url.git +refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
> git rev-parse refs/remotes/origin/${gitlabSourceBranch}^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/${gitlabSourceBranch}^{commit} # timeout=10
> git rev-parse origin/${gitlabSourceBranch}^{commit} # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE
```

Jenkins log:

```
lip 09, 2020 3:24:55 PM hudson.model.Run getEnvironment
WARNING: deprecated call to Run.getEnvironment
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
```

### Problem description

I try to send the data from GitLab to Jenkins. I tried push/merge request web hooks.
I am not able to find, why sourceBranch or targetBranch are not set.
I've not found a topic which resolves my problem.

I would be very greatful for help :(

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.