Skip to content

Instantly share code, notes, and snippets.

@viniciusvts
Last active April 22, 2024 15:55
Show Gist options
  • Save viniciusvts/0f7eab7b0cc5f019ff34c40f2dc562dd to your computer and use it in GitHub Desktop.
Save viniciusvts/0f7eab7b0cc5f019ff34c40f2dc562dd to your computer and use it in GitHub Desktop.

Config deploy

In gitlab:

If your repository is not public generate a new deploy token:

  • Go to Settings >> Repository >> Deploy Tokens
  • Generate a new Deploy Token. You get an username and a deploy_token

In Jenkins

Jenkins version tested: (ver. 2.235.2)

  • Go to settings of a project
  • Activate "this build has parameters" and create a parameter BRANCH, set the default value to a branch
  • In "Source code management" set GIT
  • In "Repository URL" set the url of repository. Example: https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git
  • In "Branch Specifier (blank for 'any')" set the parameter created: $BRANCH

If you use submodules

  • In "Additional Behaviours" add "Advanced sub-modules behaviours"
  • If you want, select the behaviors. I selected:
    • Recursively update submodules
    • Update tracking submodules to tip of branch

Config CD (continuous delivery)

In Jenkins

Jenkins version tested: (ver. 2.235.2)

  • Go to settings of a project
  • Go to "build trigger"
  • Enable "Build when a change is pushed to GitLab. GitLab webhook URL: <...>" (keep the url webhook)
  • In "Enabled GitLab triggers" select the events you want (i want only "Push Events" so disable all others options)
  • Click in advanced
  • Generate the secret token (keep secret token)
  • Save

In Gitlab

  • Go to Settings >> Integrations
  • Past the project url from Jenkins
  • Past the secret token seted in Jenkins
  • In push events set the branch name if you want
  • Disable "Enable SSL verification" if you want
  • Save clicking in "Add webhook"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment