jenkinsci / gitlab-plugin

A Jenkins plugin for interfacing with GitLab
https://plugins.jenkins.io/gitlab-plugin/
GNU General Public License v2.0
1.44k stars 614 forks source link

Defined Parameters not set/empty #785

Closed azerbe closed 6 years ago

azerbe commented 6 years ago

Issue

Context

Logs & Traces

injectedEnvVars.txt (from EnvInject Plugin)

gitlabActionType=MERGE
gitlabBranch=mergerequest
gitlabMergeRequestAssignee=Z
gitlabMergeRequestId=5
gitlabMergeRequestIid=5
gitlabMergeRequestLastCommit=712579185a9b572ec7cad6d52c00f90e49205663
gitlabMergeRequestState=opened
gitlabMergeRequestTargetProjectId=21
gitlabMergeRequestTitle=Mergerequest Test
gitlabMergedByUser=Z
gitlabSourceBranch=
gitlabSourceNamespace=Z
gitlabSourceRepoHomepage=https://git@....../Z/jenkins-docker-maven-example
gitlabSourceRepoHttpUrl=https://git@....../Z/jenkins-docker-maven-example.git
gitlabSourceRepoName=jenkins-docker-maven-example
gitlabSourceRepoSshUrl=ssh://git@....../Z/jenkins-docker-maven-example.git
gitlabSourceRepoURL=ssh://git@....../Z/jenkins-docker-maven-example.git
gitlabTargetBranch=
gitlabTargetNamespace=Z
gitlabTargetRepoHttpUrl=https://git.aqube.de/Z/jenkins-docker-maven-example.git
gitlabTargetRepoName=jenkins-docker-maven-example
gitlabTargetRepoSshUrl=ssh://git@....../Z/jenkins-docker-maven-example.git
gitlabUserEmail=mymail
gitlabUserName=myname

JenkinsJob config.xml

<?xml version='1.1' encoding='UTF-8'?>
<project>
  <actions/>
  <description>Test Project to test Jenkins&lt;-&gt;GitLab integration</description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="gitlab-plugin@1.5.6">
      <gitLabConnection>GitLab</gitLabConnection>
    </com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>
    <hudson.model.ParametersDefinitionProperty>
      <parameterDefinitions>
        <hudson.model.StringParameterDefinition>
          <name>gitlabSourceBranch</name>
          <description></description>
          <defaultValue></defaultValue>
          <trim>true</trim>
        </hudson.model.StringParameterDefinition>
        <hudson.model.StringParameterDefinition>
          <name>gitlabTargetBranch</name>
          <description></description>
          <defaultValue></defaultValue>
          <trim>true</trim>
        </hudson.model.StringParameterDefinition>
      </parameterDefinitions>
    </hudson.model.ParametersDefinitionProperty>
    <EnvInjectJobProperty plugin="envinject@2.1.5">
      <info>
        <secureGroovyScript plugin="script-security@1.44">
          <script>import hudson.model.*
def env = Thread.currentThread()?.executable.parent.builds[0].properties.get(&apos;envVars&apos;)
def map = [:]

if (env[&apos;gitlabSourceBranch&apos;] != null) {
  map[&apos;gitlabSourceBranch&apos;] = env[&apos;gitlabSourceBranch&apos;]
}
if (env[&apos;gitlabTargetBranch&apos;] != null) {
  map[&apos;gitlabTargetBranch&apos;] = env[&apos;gitlabTargetBranch&apos;]
}
// Add additional entries for any other parameters you have created

return map</script>
          <sandbox>false</sandbox>
        </secureGroovyScript>
        <loadFilesFromMaster>false</loadFilesFromMaster>
      </info>
      <on>true</on>
      <keepJenkinsSystemVariables>true</keepJenkinsSystemVariables>
      <keepBuildVariables>true</keepBuildVariables>
      <overrideBuildParameters>true</overrideBuildParameters>
    </EnvInjectJobProperty>
  </properties>
  <scm class="hudson.plugins.git.GitSCM" plugin="git@3.9.1">
    <configVersion>2</configVersion>
    <userRemoteConfigs>
      <hudson.plugins.git.UserRemoteConfig>
        <name>origin</name>
        <refspec>+refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*</refspec>
        <url>ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git</url>
        <credentialsId>f350ce1b-d303-4370-aa08-54c50ae01c79</credentialsId>
      </hudson.plugins.git.UserRemoteConfig>
    </userRemoteConfigs>
    <branches>
      <hudson.plugins.git.BranchSpec>
        <name>origin/${gitlabSourceBranch}</name>
      </hudson.plugins.git.BranchSpec>
    </branches>
    <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
    <submoduleCfg class="list"/>
    <extensions>
      <hudson.plugins.git.extensions.impl.PreBuildMerge>
        <options>
          <mergeRemote>origin</mergeRemote>
          <mergeTarget>${gitlabTargetBranch}</mergeTarget>
          <mergeStrategy>default</mergeStrategy>
          <fastForwardMode>FF</fastForwardMode>
        </options>
      </hudson.plugins.git.extensions.impl.PreBuildMerge>
    </extensions>
  </scm>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <jdk>Default</jdk>
  <triggers>
    <com.dabsquared.gitlabjenkins.GitLabPushTrigger plugin="gitlab-plugin@1.5.6">
      <spec></spec>
      <triggerOnPush>true</triggerOnPush>
      <triggerOnMergeRequest>true</triggerOnMergeRequest>
      <triggerOnPipelineEvent>false</triggerOnPipelineEvent>
      <triggerOnAcceptedMergeRequest>false</triggerOnAcceptedMergeRequest>
      <triggerOnClosedMergeRequest>false</triggerOnClosedMergeRequest>
      <triggerOnApprovedMergeRequest>false</triggerOnApprovedMergeRequest>
      <triggerOpenMergeRequestOnPush>both</triggerOpenMergeRequestOnPush>
      <triggerOnNoteRequest>true</triggerOnNoteRequest>
      <noteRegex>Jenkins please retry a build</noteRegex>
      <ciSkip>true</ciSkip>
      <skipWorkInProgressMergeRequest>true</skipWorkInProgressMergeRequest>
      <setBuildDescription>true</setBuildDescription>
      <branchFilterType>All</branchFilterType>
      <includeBranchesSpec></includeBranchesSpec>
      <excludeBranchesSpec></excludeBranchesSpec>
      <targetBranchRegex></targetBranchRegex>
      <secretToken>***********</secretToken>
      <pendingBuildName></pendingBuildName>
      <cancelPendingBuildsOnUpdate>false</cancelPendingBuildsOnUpdate>
    </com.dabsquared.gitlabjenkins.GitLabPushTrigger>
  </triggers>
  <concurrentBuild>false</concurrentBuild>
  <builders>
    <hudson.tasks.Maven>
      <targets>clean package</targets>
      <mavenName>MavenDefault</mavenName>
      <pom>pom.xml</pom>
      <usePrivateRepository>false</usePrivateRepository>
      <settings class="jenkins.mvn.DefaultSettingsProvider"/>
      <globalSettings class="jenkins.mvn.DefaultGlobalSettingsProvider"/>
      <injectBuildVariables>false</injectBuildVariables>
    </hudson.tasks.Maven>
  </builders>
  <publishers>
    <com.dabsquared.gitlabjenkins.publisher.GitLabMessagePublisher plugin="gitlab-plugin@1.5.6">
      <onlyForFailure>false</onlyForFailure>
      <replaceSuccessNote>false</replaceSuccessNote>
      <replaceFailureNote>false</replaceFailureNote>
      <replaceAbortNote>false</replaceAbortNote>
      <replaceUnstableNote>false</replaceUnstableNote>
      <successNoteText></successNoteText>
      <failureNoteText></failureNoteText>
      <abortNoteText></abortNoteText>
      <unstableNoteText></unstableNoteText>
    </com.dabsquared.gitlabjenkins.publisher.GitLabMessagePublisher>
    <com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher plugin="gitlab-plugin@1.5.6">
      <name>jenkins</name>
      <markUnstableAsSuccess>false</markUnstableAsSuccess>
    </com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher>
  </publishers>
  <buildWrappers>
    <hudson.plugins.timestamper.TimestamperBuildWrapper plugin="timestamper@1.8.10"/>
  </buildWrappers>
</project>

Jenkins Plugin-Log (after creating a new merge request)

Jun 25, 2018 9:45:31 AMJun 25, 2018   INFO com.dabsquared.gitlabjenkins.webhook.GitLabWebHook getDynamic
WebHook called with url: /project/jenkins-docker-maven-example
Jun 25, 2018 9:45:31 AM FINE com.dabsquared.gitlabjenkins.webhook.build.MergeRequestBuildAction
MergeRequest: {
  "object_kind" : "merge_request",
  "event_type" : "merge_request",
  "user" : {
    "name" : "Alex",
    "username" : "Z",
    "avatar_url" : null
  },
  "project" : {
    "id" : 21,
    "name" : "jenkins-docker-maven-example",
    "description" : "",
    "web_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example",
    "avatar_url" : null,
    "git_ssh_url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
    "git_http_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example.git",
    "namespace" : "Z",
    "visibility_level" : 0,
    "path_with_namespace" : "Z/jenkins-docker-maven-example",
    "default_branch" : "master",
    "ci_config_path" : null,
    "homepage" : "https://git.mydomain.com/Z/jenkins-docker-maven-example",
    "url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
    "ssh_url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
    "http_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example.git"
  },
  "object_attributes" : {
    "assignee_id" : 4,
    "author_id" : 4,
    "created_at" : "2018-06-25 09:45:31 UTC",
    "description" : "",
    "head_pipeline_id" : 10,
    "id" : 5,
    "iid" : 5,
    "last_edited_at" : null,
    "last_edited_by_id" : null,
    "merge_commit_sha" : null,
    "merge_error" : null,
    "merge_params" : {
      "force_remove_source_branch" : "0"
    },
    "merge_status" : "unchecked",
    "merge_user_id" : null,
    "merge_when_pipeline_succeeds" : false,
    "milestone_id" : null,
    "source_branch" : "mergerequest",
    "source_project_id" : 21,
    "state" : "opened",
    "target_branch" : "master",
    "target_project_id" : 21,
    "time_estimate" : 0,
    "title" : "Mergerequest Test",
    "updated_at" : "2018-06-25 09:45:31 UTC",
    "updated_by_id" : null,
    "url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example/merge_requests/5",
    "source" : {
      "id" : 21,
      "name" : "jenkins-docker-maven-example",
      "description" : "",
      "web_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example",
      "avatar_url" : null,
      "git_ssh_url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
      "git_http_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example.git",
      "namespace" : "Z",
      "visibility_level" : 0,
      "path_with_namespace" : "Z/jenkins-docker-maven-example",
      "default_branch" : "master",
      "ci_config_path" : null,
      "homepage" : "https://git.mydomain.com/Z/jenkins-docker-maven-example",
      "url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
      "ssh_url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
      "http_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example.git"
    },
    "target" : {
      "id" : 21,
      "name" : "jenkins-docker-maven-example",
      "description" : "",
      "web_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example",
      "avatar_url" : null,
      "git_ssh_url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
      "git_http_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example.git",
      "namespace" : "Z",
      "visibility_level" : 0,
      "path_with_namespace" : "Z/jenkins-docker-maven-example",
      "default_branch" : "master",
      "ci_config_path" : null,
      "homepage" : "https://git.mydomain.com/Z/jenkins-docker-maven-example",
      "url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
      "ssh_url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
      "http_url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example.git"
    },
    "last_commit" : {
      "id" : "712579185a9b572ec7cad6d52c00f90e49205663",
      "message" : "Merge-Request-Update-Test2\n",
      "timestamp" : "2018-06-25T10:31:23+02:00",
      "url" : "https://git.mydomain.com/Z/jenkins-docker-maven-example/commit/712579185a9b572ec7cad6d52c00f90e49205663",
      "author" : {
        "name" : "myname",
        "email" : "myname@mydomain.com"
      }
    },
    "work_in_progress" : false,
    "total_time_spent" : 0,
    "human_total_time_spent" : null,
    "human_time_estimate" : null,
    "action" : "open"
  },
  "labels" : [ ],
  "changes" : {
    "head_pipeline_id" : {
      "previous" : null,
      "current" : 10
    },
    "updated_at" : {
      "previous" : "2018-06-25 09:45:31 UTC",
      "current" : "2018-06-25 09:45:31 UTC"
    },
    "assignee" : {
      "previous" : null,
      "current" : {
        "name" : "Alex",
        "username" : "Z",
        "avatar_url" : null
      }
    },
    "total_time_spent" : {
      "previous" : null,
      "current" : 0
    }
  },
  "repository" : {
    "name" : "jenkins-docker-maven-example",
    "url" : "ssh://git@git.mydomain.com/Z/jenkins-docker-maven-example.git",
    "description" : "",
    "homepage" : "https://git.mydomain.com/Z/jenkins-docker-maven-example"
  },
  "assignee" : {
    "name" : "Alex",
    "username" : "Z",
    "avatar_url" : null
  }
}
Jun 25, 2018 9:45:31 AM INFO com.dabsquared.gitlabjenkins.trigger.handler.AbstractWebHookTriggerHandler handle
jenkins-docker-maven-example triggered for merge request.
Jun 25, 2018 9:45:31 AM FINEST com.dabsquared.gitlabjenkins.gitlab.api.impl.ResteasyGitLabClientBuilder
Call GitLab:
HTTP method: POST
URL: https://git.mydomain.com/api/v4/projects/21/statuses/712579185a9b572ec7cad6d52c00f90e49205663
Request headers: [
Accept = [application/json],
Content-Type = [application/x-www-form-urlencoded],
PRIVATE-TOKEN = [****FILTERED****]
]
Jun 25, 2018 9:45:32 AM FINEST com.dabsquared.gitlabjenkins.gitlab.api.impl.ResteasyGitLabClientBuilder
Got response from GitLab:
URL: https://git.mydomain.com/api/v4/projects/21/statuses/712579185a9b572ec7cad6d52c00f90e49205663
Status: 201 Created
Response headers: [
Cache-Control = [max-age=0, private, must-revalidate],
Connection = [keep-alive],
Content-Length = [481],
Content-Type = [application/json],
Date = [Mon, 25 Jun 2018 09:45:32 GMT],
Etag = [W/"e45716983dc0daa641f5f45946bd9a5b"],
Server = [nginx],
Strict-Transport-Security = [max-age=31536000],
Vary = [Origin],
X-Content-Type-Options = [nosniff],
X-Frame-Options = [SAMEORIGIN],
X-Request-Id = [78bd3057-bf58-4647-b426-aaf0aeb1fc1e],
X-Runtime = [0.232203]
]
Response body: {
  "id" : 62,
  "sha" : "712579185a9b572ec7cad6d52c00f90e49205663",
  "ref" : "mergerequest",
  "status" : "pending",
  "name" : "jenkins",
  "target_url" : "https://jenkins.mydomain.com/job/jenkins-docker-maven-example/display/redirect",
  "description" : "pending",
  "created_at" : "2018-06-25T09:45:32.138Z",
  "started_at" : null,
  "finished_at" : null,
  "allow_failure" : false,
  "coverage" : null,
  "author" : {
    "id" : 6,
    "name" : "Jenkins User",
    "username" : "jenkins",
    "state" : "active",
    "avatar_url" : null,
    "web_url" : "https://git.mydomain.com/jenkins"
  }
}
Jun 25, 2018 9:45:41 AM FINEST com.dabsquared.gitlabjenkins.gitlab.api.impl.ResteasyGitLabClientBuilder
Call GitLab:
HTTP method: POST
URL: https://git.mydomain.com/api/v4/projects/21/merge_requests/5/notes
Request headers: [
Accept = [application/json],
Content-Type = [application/x-www-form-urlencoded],
PRIVATE-TOKEN = [****FILTERED****]
]
Jun 25, 2018 9:45:41 AM FINEST com.dabsquared.gitlabjenkins.gitlab.api.impl.ResteasyGitLabClientBuilder
Got response from GitLab:
URL: https://git.mydomain.com/api/v4/projects/21/merge_requests/5/notes
Status: 201 Created
Response headers: [
Cache-Control = [max-age=0, private, must-revalidate],
Connection = [keep-alive],
Content-Length = [548],
Content-Type = [application/json],
Date = [Mon, 25 Jun 2018 09:45:41 GMT],
Etag = [W/"221c34494f138df9fe8dd069ad13712e"],
Server = [nginx],
Strict-Transport-Security = [max-age=31536000],
Vary = [Origin],
X-Content-Type-Options = [nosniff],
X-Frame-Options = [SAMEORIGIN],
X-Request-Id = [756dbb87-89ff-4957-a1a6-d227c34d9933],
X-Runtime = [0.105349]
]
Response body: {
  "id" : 14,
  "type" : null,
  "body" : ":negative_squared_cross_mark: Jenkins Build FAILURE\n\nResults available at: [Jenkins [jenkins-docker-maven-example #25]](https://jenkins.mydomain.com/job/jenkins-docker-maven-example/25/)",
  "attachment" : null,
  "author" : {
    "id" : 6,
    "name" : "Jenkins User",
    "username" : "jenkins",
    "state" : "active",
    "avatar_url" : null,
    "web_url" : "https://git.mydomain.com/jenkins"
  },
  "created_at" : "2018-06-25T09:45:41.129Z",
  "updated_at" : "2018-06-25T09:45:41.129Z",
  "system" : false,
  "noteable_id" : 5,
  "noteable_type" : "MergeRequest",
  "resolvable" : false,
  "noteable_iid" : 5
}
Jun 25, 2018 9:45:41 AM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Jun 25, 2018 9:45:41 AM FINEST com.dabsquared.gitlabjenkins.gitlab.api.impl.ResteasyGitLabClientBuilder
Call GitLab:
HTTP method: GET
URL: https://git.mydomain.com/api/v4/projects/21/repository/commits/712579185a9b572ec7cad6d52c00f90e49205663
Request headers: [
Accept = [application/json],
PRIVATE-TOKEN = [****FILTERED****]
]
Jun 25, 2018 9:45:41 AM FINEST com.dabsquared.gitlabjenkins.gitlab.api.impl.ResteasyGitLabClientBuilder
Got response from GitLab:
URL: https://git.mydomain.com/api/v4/projects/21/repository/commits/712579185a9b572ec7cad6d52c00f90e49205663
Status: 200 OK
Response headers: [
Cache-Control = [max-age=0, private, must-revalidate],
Connection = [keep-alive],
Content-Length = [681],
Content-Type = [application/json],
Date = [Mon, 25 Jun 2018 09:45:41 GMT],
Etag = [W/"d0f097d7eba2dd3a29eb6bca10176ff0"],
Server = [nginx],
Strict-Transport-Security = [max-age=31536000],
Vary = [Origin],
X-Content-Type-Options = [nosniff],
X-Frame-Options = [SAMEORIGIN],
X-Request-Id = [6f78c496-be43-4aff-9162-4cbd70f468ca],
X-Runtime = [0.061709]
]
Response body: {
  "id" : "712579185a9b572ec7cad6d52c00f90e49205663",
  "short_id" : "71257918",
  "title" : "Merge-Request-Update-Test2",
  "created_at" : "2018-06-25T10:31:23.000+02:00",
  "parent_ids" : [ "3e226e8755618c695e7e20db962f9c66b0645241" ],
  "message" : "Merge-Request-Update-Test2\n",
  "author_name" : "myname",
  "author_email" : "myname@mydomain.com",
  "authored_date" : "2018-06-25T10:31:23.000+02:00",
  "committer_name" : "myname",
  "committer_email" : "myname@mydomain.com",
  "committed_date" : "2018-06-25T10:31:23.000+02:00",
  "stats" : {
    "additions" : 1,
    "deletions" : 0,
    "total" : 1
  },
  "status" : "running",
  "last_pipeline" : {
    "id" : 10,
    "sha" : "712579185a9b572ec7cad6d52c00f90e49205663",
    "ref" : "mergerequest",
    "status" : "running"
  },
  "project_id" : 21
}
Jun 25, 2018 9:45:41 AM FINEST com.dabsquared.gitlabjenkins.gitlab.api.impl.ResteasyGitLabClientBuilder
Call GitLab:
HTTP method: POST
URL: https://git.mydomain.com/api/v4/projects/21/statuses/712579185a9b572ec7cad6d52c00f90e49205663
Request headers: [
Accept = [application/json],
Content-Type = [application/x-www-form-urlencoded],
PRIVATE-TOKEN = [****FILTERED****]
]
Jun 25, 2018 9:45:41 AM FINEST com.dabsquared.gitlabjenkins.gitlab.api.impl.ResteasyGitLabClientBuilder
Got response from GitLab:
URL: https://git.mydomain.com/api/v4/projects/21/statuses/712579185a9b572ec7cad6d52c00f90e49205663
Status: 201 Created
Response headers: [
Cache-Control = [max-age=0, private, must-revalidate],
Connection = [keep-alive],
Content-Length = [504],
Content-Type = [application/json],
Date = [Mon, 25 Jun 2018 09:45:41 GMT],
Etag = [W/"2fc3406b7cb6496abc371de498dbee1f"],
Server = [nginx],
Strict-Transport-Security = [max-age=31536000],
Vary = [Origin],
X-Content-Type-Options = [nosniff],
X-Frame-Options = [SAMEORIGIN],
X-Request-Id = [cd3fd6da-2be6-4c8b-b36b-346fa2a82dff],
X-Runtime = [0.259783]
]
Response body: {
  "id" : 62,
  "sha" : "712579185a9b572ec7cad6d52c00f90e49205663",
  "ref" : "mergerequest",
  "status" : "failed",
  "name" : "jenkins",
  "target_url" : "https://jenkins.mydomain.com/job/jenkins-docker-maven-example/25/display/redirect",
  "description" : "failed",
  "created_at" : "2018-06-25T09:45:32.138Z",
  "started_at" : null,
  "finished_at" : "2018-06-25T09:45:41.456Z",
  "allow_failure" : false,
  "coverage" : null,
  "author" : {
    "id" : 6,
    "name" : "Jenkins User",
    "username" : "jenkins",
    "state" : "active",
    "avatar_url" : null,
    "web_url" : "https://git.mydomain.com/jenkins"
  }
}

Problem description

Before I've setup Gitlab, Jenkins, gitlab-plugin and a jenkins job (Freestyle, parameterized) following the documentation.

When I start the build by hand (From Jenkins) and insert branchnames into the parameter fields, everything is working fine.

When I create a merge-request or push a commit to the repository, the webhook triggers the build correctly, but the parameters that have been set in the configuration are empty. (gitlabSourceBranch and gitlabTargetBranch) Every other parameter is working fine.

Then the build fails, cause it can't pull.

azerbe commented 6 years ago

Sidenote: If I remove the parameters from the jenkinsjob (not the EnvPlugin) and keep it parameterized, the build also works.

So at some place the submitted environment variables are getting replaced by the empty ones, defined in the jenkins-job.

omehegan commented 6 years ago

@azerbe can you share the envinject code you are using to set the variables? Also, in your "sidenote" comment, I don't understand what you mean when you say you remove the parameters and keep it parameterized.

azerbe commented 6 years ago

Hello @omehegan ,

thanks for the response.

Following the Env-Variables:

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

if (env['gitlabSourceBranch'] != null) { 
  map['gitlabSourceBranch'] = env['gitlabSourceBranch'] 
}
if (env['gitlabTargetBranch'] != null) { 
  map['gitlabTargetBranch'] = env['gitlabTargetBranch'] 
}
// Add additional entries for any other parameters you have created

return map

Forget my comment about the parameterized configuration. I just left the checkmark for This build is parameterized, but Jenkins removes that if you don't have any parameters configured.

The base problem still remains. If I add two text parameters named gitlabSouceBranch and gitlabTargetBranch to the jenkins build, they overwrite the values provided by the gitlab-plugin with an empty string.

Do I have to add some default Values?

omehegan commented 6 years ago

I got the envinject code for this from @ElijahLynn in another issue, and added it to the README. Maybe he can help you out with this. Please let me know if it turns out I need to change something in the doc.

azerbe commented 6 years ago

I don't think this code is wrong. I use it without the parameters set and it works. But I would like to be able to start a build by hand from time to time. And I don't know how to debug the plugin to see, when the values are being overwritten.

omehegan commented 6 years ago

The whole point of that code was to allow you to do exactly what you are trying to do, so if it's not working we'll have to figure it out :) See https://github.com/jenkinsci/gitlab-plugin/issues/356#issuecomment-385594555

azerbe commented 6 years ago

The question is, if i named the parameters wrong. @ElijahLynn called them sourceBranch instead of gitlabSourceBranch in his comment. I can check that later.

Just for clarification:

image

ElijahLynn commented 6 years ago

K, it looks like the documentation commit wasn't precisely what my code was/is, here is what is working right now for my team:

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['gitlabTargetBranch'] != null) { 
  map['TargetBranch'] = env['gitlabTargetBranch'] 
}

return map

image

image

ElijahLynn commented 6 years ago

I created the PR above, the only thing that differs from it and the comment above is that it uses the Java variable naming convention of sourceBranch vs SourceBranch. Hopefully this helps you out.

ElijahLynn commented 6 years ago

One caveat that we haven't figured out yet though is that when a build is pending, and you hover over the pending build to get information on it, the branch names are not in that info. However, if you go up a level and look at all pending jobs, the information is available.

omehegan commented 6 years ago

@azerbe can you confirm if you have this working now? I guess when I wrote the doc update I incorrectly assumed the variables could be overwritten, and that resulted in a broken example.

azerbe commented 6 years ago

Thanks for the replies. Kinda busy right now, but will look into it in the next days and give feedback.

azerbe commented 6 years ago

Okay, if you rename the String-Parameters and also the Branch Specifier and Branch to merge to blocks, it works.

Please also update the documentation, so that Branch Specifier and Branch to merge to are updated as well and everything is up to date again. :)

Please update #791

jenkins-docker-maven-example_config__jenkins_

Thanks for the clarification guys!

omehegan commented 6 years ago

@azerbe and @ElijahLynn thanks for helping me improve the docs!

ElijahLynn commented 6 years ago

@azerbe Good catch, we do have the branch specifier and branch to merge AND "Calculate changelog against a specific branch" specified as well (ignore the casing in mine, we haven't changed it yet).

image

dastanko commented 5 years ago

Hi, guys does it also works for pipeline configuration? I followed instructions on readme and see that declared parameters override parameters coming from a web hook even though I applied the solution with Env.Inject.

devops-tavus commented 1 year ago

@dastanko were you able to do this for pipeline? I am facing the same problem.