Closed jostyee closed 6 years ago
There is also ProjectIid perhaps that works if you try it.
@tomasbjerre No there isn't any projectlid env var.
So you can do this?
curl -XGET "https://gitlab.com/api/v4/projects/253"
@tomasbjerre sure.
curl -XGET "https://gitlab.company.com/api/v4/projects/253?private_token=personal_access_token"
{"id":253,"description":"","default_branch":"master","tag_list":[],"ssh_url_to_repo":"git@gitlab.company.com:group/demo-grpc.git","http_url_to_repo":"https://gitlab.company.com/group/demo-grpc.git","web_url":"https://gitlab.company.com/group/demo-grpc","name":"demo-grpc","name_with_namespace":"group / demo-grpc","path":"demo-grpc","path_with_namespace":"group/demo-grpc","star_count":0,"forks_count":0,"created_at":"2017-02-28T19:21:53.133+08:00","last_activity_at":"2017-11-01T18:07:11.090+08:00","_links":{"self":"http://gitlab.company.com/api/v4/projects/253","issues":"http://gitlab.company.com/api/v4/projects/253/issues","merge_requests":"http://gitlab.company.com/api/v4/projects/253/merge_requests","repo_branches":"http://gitlab.company.com/api/v4/projects/253/repository/branches","labels":"http://gitlab.company.com/api/v4/projects/253/labels","events":"http://gitlab.company.com/api/v4/projects/253/events","members":"http://gitlab.company.com/api/v4/projects/253/members"},"archived":false,"visibility":"internal","resolve_outdated_diff_discussions":null,"container_registry_enabled":true,"issues_enabled":true,"merge_requests_enabled":true,"wiki_enabled":false,"jobs_enabled":true,"snippets_enabled":false,"shared_runners_enabled":true,"lfs_enabled":true,"creator_id":8,"namespace":{"id":32,"name":"group","path":"group","kind":"group","full_path":"group","parent_id":null},"import_status":"none","avatar_url":null,"open_issues_count":2,"public_jobs":true,"ci_config_path":null,"shared_with_groups":[],"only_allow_merge_if_pipeline_succeeds":false,"request_access_enabled":false,"only_allow_merge_if_all_discussions_are_resolved":false,"printing_merge_request_link_enabled":true,"permissions":{"project_access":null,"group_access":{"access_level":30,"notification_level":3}}}
I guess the plugin doesn't pass GitLab personal access token when querying this API?
The API token is passed to the Java Gitlab API: https://github.com/tomasbjerre/violation-comments-to-gitlab-lib/blob/master/src/main/java/se/bjurr/violations/comments/gitlab/lib/GitLabCommentsProvider.java#L41
Can you do that curl command from the server running Jenkins?
I did execute the command from the host server of Jenkins. Is there any issue with the official Jenkins docker image? we're running it as a container.
If you update the plugin to 1.16 you will get more information in the exception. It will include the chained exception from the library.
@tomasbjerre The API query was not set right, token param name should be private_token
other than access_token
15:27:58 Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: https://gitlab.company.com/api/v4/projects/253?access_token=personal_access_token
15:27:58 at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
15:27:58 at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
15:27:58 at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
15:27:58 at org.gitlab.api.http.GitlabHTTPRequestor.parse(GitlabHTTPRequestor.java:394)
15:27:58 at org.gitlab.api.http.GitlabHTTPRequestor.to(GitlabHTTPRequestor.java:168)
15:27:58 ... 21 more
refer to https://docs.gitlab.com/ce/api/README.html#personal-access-tokens, my above comment showed a working log: https://github.com/jenkinsci/violation-comments-to-gitlab-plugin/issues/8#issuecomment-341235656
It looks like you did not check the "Private token" checkbox in the GUI.
@tomasbjerre Not the Use API token
input?
You need both.
Is this solved?
I'm sorry to forget to reply here, I've switched to other solution so this is not an issue for me any longer.
Hi, I'm experiencing this same issue...
I have a pipeline project, my project is being triggered via gitlab webhook plugin, gitlab.com, last version of your plugin and last jenkins version
I'm using the following call in my pipeline script and the parameters have this format
gitlabTargetRepoHttpUrl=https://gitlab.com/user/repo.git
gitlabMergeRequestTargetProjectId=0000000
I have tryed with either
gitlabMergeRequestIid=000 or gitlabMergeRequestId=0000000
ViolationsToGitLab([
gitLabUrl: env.gitlabTargetRepoHttpUrl, projectId: env.gitlabMergeRequestTargetProjectId,
mergeRequestId: env.gitlabMergeRequestIid, commentOnlyChangedContent: true,
createCommentWithAllSingleFileComments: true, minSeverity: 'INFO',
apiToken: 'XXXXXXXXXXXXXXXXXXXX', apiTokenPrivate: true,
authMethodHeader: true, ignoreCertificateErrors: true, keepOldComments: false,
violationConfigs: [[ pattern: '.*/pmddelta.xml$', parser: 'PMD', reporter: 'PMD' ]]
])
Will comment PR https://gitlab.com/user/repo.git 0000000 000
[Code Quality Tests] java.lang.RuntimeException: Could not get project 0000000
[Code Quality Tests] at se.bjurr.violations.comments.gitlab.lib.GitLabCommentsProvider.<init>(GitLabCommentsProvider.java:51)
[Code Quality Tests] at se.bjurr.violations.comments.gitlab.lib.ViolationCommentsToGitLabApi.toPullRequest(ViolationCommentsToGitLabApi.java:125)
[Code Quality Tests] at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer.doPerform(JvctglPerformer.java:142)
[Code Quality Tests] at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$1.invoke(JvctglPerformer.java:227)
[Code Quality Tests] at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer$1.invoke(JvctglPerformer.java:215)
[Code Quality Tests] at hudson.FilePath.act(FilePath.java:1009)
[Code Quality Tests] at hudson.FilePath.act(FilePath.java:987)
[Code Quality Tests] at org.jenkinsci.plugins.jvctgl.perform.JvctglPerformer.jvctsPerform(JvctglPerformer.java:214)
[Code Quality Tests] at org.jenkinsci.plugins.jvctgl.ViolationsToGitLabRecorder.perform(ViolationsToGitLabRecorder.java:64)
[Code Quality Tests] at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
[Code Quality Tests] at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
[Code Quality Tests] at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
[Code Quality Tests] at hudson.security.ACL.impersonate(ACL.java:290)
[Code Quality Tests] at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
[Code Quality Tests] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[Code Quality Tests] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[Code Quality Tests] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[Code Quality Tests] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[Code Quality Tests] at java.lang.Thread.run(Thread.java:748)
[Code Quality Tests] Caused by: java.io.FileNotFoundException: https://gitlab.com/user/repo.git/api/v4/projects/0000000
[Code Quality Tests] at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1890)
[Code Quality Tests] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
[Code Quality Tests] at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
[Code Quality Tests] at org.gitlab.api.http.GitlabHTTPRequestor.parse(GitlabHTTPRequestor.java:394)
[Code Quality Tests] at org.gitlab.api.http.GitlabHTTPRequestor.to(GitlabHTTPRequestor.java:168)
[Code Quality Tests] at org.gitlab.api.http.GitlabHTTPRequestor.to(GitlabHTTPRequestor.java:139)
[Code Quality Tests] at org.gitlab.api.GitlabAPI.getProject(GitlabAPI.java:610)
[Code Quality Tests] at se.bjurr.violations.comments.gitlab.lib.GitLabCommentsProvider.<init>(GitLabCommentsProvider.java:49)
[Code Quality Tests] ... 18 more
[Code Quality Tests]
Change gitLabUrl: env.gitlabTargetRepoHttpUrl
to gitLabUrl: 'https://gitlab.com/'
.
I'm releasing a new version to clarify the gitlabMergeRequestI(i)d
.
Managed to get it working with env.gitlabMergeRequestIid, the only bad thing is that the GitLab plugin does not provide an env variable that contains the URL so we would have to cut gitlabTargetRepoHttpUrl
Thank you @tomasbjerre !
You could try my generic-webhook-trigger-plugin: https://github.com/jenkinsci/generic-webhook-trigger-plugin/blob/master/src/test/resources/org/jenkinsci/plugins/gwt/bdd/gitlab/gitlab-mergerequest.feature
My Env:
I setup violation comments gitlab plugin as below:
It threw an exception when running its Post-build Action:
In fact GitLab project 253 exists.