Closed benmathews closed 1 year ago
How you get the values depends on what plugin you used to trigger the build.
Gitlab.com cannot be hardcoded because some people host it themselves.
Any hints on setting up the credentials. That is my blocker.
Here is how I set it up, last time I used it: https://github.com/tomasbjerre/jenkins-configuration-as-code-sandbox/blob/007e7a11e15b317dc4a250dc9344230a5580aae3/jenkins-docker/jenkins.yaml#L31
And I supply it to the plugin here: https://github.com/tomasbjerre/jenkins-configuration-as-code-sandbox/blob/57f4df6d8df47d3b93ffea76f792564003ec3c36/vars/buildRepo.groovy#L148
Also another hint is to use the pipeline syntax GUI in Jenkins: Have that generate pipeline code that sets the credential correctly.
With the above hints, I was able to get the plugin working.
The most significant issue was the credential. The plugin requires a StringCredentials
. In the GUI, I created a "Gitlab Personal Access Token" which seemed reasonable. In looking at the XML representation, I saw that this wasn't resulting in the string type. I determined that the "Secret Text" credential type in the GUI is what I needed.
The projected needs to be either the id
or path_with_namespace
value returned from https://gitlab.com/api/v4/projects
@benmathews 's comment is super helpful! thanks. Might i suggest that the other access token mechanisms be supported at some point? nothing more frustrating that putting in credentials and have them disappear. where they saved somewhere or not? don't know lol
I'm struggling with configuring this plugin. It is absolutely not clear how to include this plugin in a pipeline (Jenkinsfile).
My Configuration
pipeline {
other stages
stage('Quality Gate') {
steps {
updateGitlabCommitStatus name: 'Quality Gate', state: 'pending'
timeout(time: 5, unit: 'MINUTES') {
waitForQualityGate(credentialsId: 'sonar-api-token', abortPipeline: false)
}
updateGitlabCommitStatus name: 'Quality Gate', state: 'success'
withCredentials([string(credentialsId: 'GITLAB_API_TOKEN', variable: 'TOKEN')]) {
ViolationsToGitLabRecorder([
apiTokenCredentialsId: TOKEN,
apiTokenPrivate: true,
authMethodHeader: true,
commentOnlyChangedContent: true,
commentTemplate: violationReporterTemplate() ,
createSingleFileComments: true,
gitLabUrl: <url_to_our_gitlab',
ignoreCertificateErrors: true,
keepOldComments: false,
mergeRequestIid: MR_IID,
minSeverity: 'INFO',
projectId: MR_PROJECT_ID,
violationConfigs: [
[ pattern: '.*/test-results/test/.*\\.xml$', parser: 'JUNIT', reporter: 'JUnit' ],
[ pattern: '.*/jacoco/.*\\.exec$', parser: 'JACOCO', reporter: 'Jacoco' ]
]
])
}
}
}
}
I also tried
stage("Report") {
ViolationsToGitLab([
apiTokenCredentialsId: 'gitlab-token',
and
step([
$class: 'ViolationsToGitLabRecorder',
config: [
described here https://github.com/jenkinsci/violation-comments-to-gitlab-plugin
Errors: java.lang.NoSuchMethodError: No such DSL method 'ViolationsToGitLabRecorder' java.lang.NoSuchMethodError: No such DSL method 'ViolationsToGitLab' or ClassDefNotFound
The plugin is installed.
@tomasbjerre i don't have problems with the credentials. Can't find an entry in the pipeline editor for this plugin.
If you cannot find it, it might not be installed.
If you cannot find it, it might not be installed.
If i take a look into installed plugins it's shown as installed.
Here is where it should show up:
Describe your use-case which is not covered by existing documentation.
There are a couple of configuration items that I'm struggling with.
env.PROJECT_PATH
doesn't exist. I've guessed atenv.GITLAB_PROJECT_ID
?env.MERGE_REQUST_IID
doesn't exist. I'm assumingenv.CHANGE_ID
?The env variables that might be useful are
Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.
No response