gitlab-branch-source-plugin | Jenkins Plugin for GitLab Multibranch Pipeline jobs | Continous Integration library
kandi X-RAY | gitlab-branch-source-plugin Summary
kandi X-RAY | gitlab-branch-source-plugin Summary
To be fully able to run a Jenkins Continuous Integration on a GitLab repository or project, you require the following plugins:.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Sends notifications for a build
- Retrieves the source project ID from a MR job
- Gets the revision ref
- Retrieve actions for SCM head events
- Retrieves the actions for the SCM project
- Retrieve actions for a SCM head
- Gets the project s projects
- Get the name of the project based on the given project name
- Obtain credentials for the given SCM scope
- Returns a map of SCMS revisions for the given SCM source
- Handles an HTTP POST request
- Handles a POST request
- Get the children of this directory
- Retrieves a directed revision
- Adds Gitlab environment variables to the environment
- Returns the type of a push event
- Get the type of a file
- Gets list of projects from server
- Decorate the context
- Create a token using the given credentials id
- Builds the SCM HEAD
- Reserves a cached image
- Log comment on build
- Retrieves the actions of the given owner
- Creates a new SCM probe
- Checks if the message is a merge request
gitlab-branch-source-plugin Key Features
gitlab-branch-source-plugin Examples and Code Snippets
Community Discussions
Trending Discussions on gitlab-branch-source-plugin
QUESTION
I am trying the access the values set on a job's configuration page from within my pipeline. These values are not made available as params, nor are they injected as envvars.
Setup
- Jenkins, v2.263.1
- GitLab Branch Source plugin, v1.5.3 (link)
- Multibranch pipeline job which is pointed to a Gitlab repo
- Remote Jenkinsfile Provider, v1.13 (link)
Problem
Ordinarily, one would have a Jenkinsfile in the root of the repo and therefore the scm would be associated with the repo we want to checkout and build. However, in my case the code I want to build is in a different repo to the Jenkinsfile (hence the Remote Jenkinsfile Provider plugin).
This means that I need to checkout the code I wish to build as an explicit step in the pipeline, and to do that I need to know the repo. This repo is, however, already defined in the job config.
The Branch Source plugin does export things like the branch name or merge request number/branch/target into appropriate envvars, but NOT the actual repo.
As this is a multibranch pipeline, I cannot use something like envInject either (multibranch jobs do not provide the option to 'Prepare an environment for the run' as with other jobs)
Goal
I would like to be able to access the server
, owner
and project
fields set in the job config page. Ultimately I could manage with just the project's ssh/http address even.
Is there some clever way of accessing a job's config from within the pipeline?
Thanks for any suggestions!
Reference images
...ANSWER
Answered 2021-Jan-25 at 19:37Within the gitlab branch source plugin (and the documentation) you have a lot more information, than just with the normal branch source plugin. there are environment variables for the project like GITLAB_PROJECT_GIT_SSH_URL
/GITLAB_PROJECT_GIT_HTTPS_URL
for the git source and many more. So far i did not see one for the server, but that would be parse-able our of the URLs.
Within this information, it should be fairly easy to checkout the repository and build it.
As through the process it came clear, that it is needed to also trigger the pipeline manually, and this is normally also possible with variables (not sure about the Remote File plugin). I assume your Jenkinsfile is a groovy script, which opens up a lot of possibilities. You can define variables and use some logic to determine if the env variable or the parameter is used.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install gitlab-branch-source-plugin
After installing the plugin on your Jenkins instance, you need configure your GitLab Server settings.
On jenkins, select Manage Jenkins. Scroll down to find the GitLab section. Select Add GitLab Server | Select GitLab Server. Now you will now see the GitLab Server Configuration options.
On jenkins, select Manage Jenkins.
Select Configure System.
Scroll down to find the GitLab section.
Select Add GitLab Server | Select GitLab Server.
Now you will now see the GitLab Server Configuration options There are 4 fields that needs to be configured: i. Name - Plugin automatically generates an unique server name for you. User may want to configure this field to suit their needs but should make sure it is sufficiently unique. We recommend to keep it as it is. ii. Server URL - Contains the URL to your GitLab Server. By default it is set to "https://gitlab.com". User can modify it to enter their GitLab Server URL e.g. https://gitlab.gnome.org/, http://gitlab.example.com:7990. etc. iii. Credentials - Contains a list of credentials entries that are of type GitLab Personal Access Token. When no credential has been added it shows "-none-". User can add a credential by clicking "Add" button. iv. Mange Web Hook - If you want the plugin to setup web hook on your GitLab project(s) to get push/mr/tag/note events then check this box. iv. Mange System Hook - If you want the plugin to setup system hook on your GitLab project(s) to detect if a project is removed then check this box. Remember plugin can only setup system hook on your server if supplied access token has Admin access. v. Secret Token - The secret token is required to authenticate the webhook payloads received from GitLab Server. Use generate secret token from Advanced options or use your own. If you are a old plugin user and did not set a secret token previously and want secret token to applied to the hooks of your existing jobs, you can add the secret token and rescan your jobs. Existing hooks with new secret token will be applied. vi. Root URL for hooks - By default Root URL for hooks created by this plugin is your Jenkins instance url. You can modify the root URL in by adding your custom root URL. Leave empty if you want Jenkins URL to be your custom hook url. A path is added to your hook ROOT URL /gitlab-webhook/post for webhooks and /gitlab-systemhook/post for system hooks.
Adding a Personal Access Token Credentials: This is a manual setup. To automatically generate Personal Access Token see next section. i. User is required to add a GitLab Personal Access Token type credentials entry to securely persist the token inside Jenkins. ii. Generate a Personal Access Token on your GitLab Server a. Select profile dropdown menu from top-right corner b. Select `Settings` c. Select `Access Token` from left column d. Enter a name | Set Scope to `api` (If admin also give `sudo` which required for systemhooks and mr comment trigger) e. Select `Create Personal Access Token` f. Copy the token generated iii. Return to Jenkins | Select Add in Credentials field | Select Jenkins. iv. Set Kind to GitLab Personal Access Token. v. Enter Token. vi. Enter a unique id in ID. vii. Enter a human readable description. viii. Select Add.
Testing connection: i. Select your desired token in the Credentials dropdown. ii. Select Test Connection. iii. It should return something like Credentials verified for user {username}.
Select Apply (at the bottom).
GitLab Server is now setup on Jenkins.
GitLab Branch Source Plugin allows you to create 2 type of jobs:.
Multibranch Pipeline Jobs - For single project.
Folder Organisation - For multiple projects inside a owner (user/group/subgroup).
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page