{"id":8344,"date":"2024-11-26T11:36:31","date_gmt":"2024-11-26T06:06:31","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=8344"},"modified":"2025-02-17T17:30:44","modified_gmt":"2025-02-17T12:00:44","slug":"how-to-configure-the-bitbucket-credentials-in-jenkins","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-configure-the-bitbucket-credentials-in-jenkins\/","title":{"rendered":"How to Configure the Bitbucket credentials in Jenkins"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Introduction : <\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Configuring Git credentials in Jenkins is essential for automating your build and deployment pipelines. By securely storing and managing your Git credentials, you can:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Automate CI\/CD pipelines<strong>:<\/strong> Seamlessly integrate Git repositories into your Jenkins jobs for automated builds, tests, and deployments.<\/li>\n\n\n\n<li>Enhance security: Protect sensitive information like usernames and passwords by storing them securely within Jenkins.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites : <\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A running Jenkins server<\/li>\n\n\n\n<li>A Git repository and Git access<\/li>\n\n\n\n<li>Jenkins administrator privileges<\/li>\n\n\n\n<li>Required necessary plugins (e.g., Git Plugin, Credentials Plugin).<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Configure :<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Step-1:-SSH-Key-Pair-for-Jenkins-User\">Step 1: SSH Key Pair for Jenkins User<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Switch to Jenkins User<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo su - jenkins<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">View the Public Key and copy that Key<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cat ~\/.ssh\/id_rsa.pub<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Step-2:-Add-Public-Key-to-Bitbucket\">Step 2: Add Public Key to Bitbucket<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Log in to Bitbucket<\/strong>:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Navigate to <strong>Personal settings<\/strong> &gt; <strong>SSH keys<\/strong>.<\/li>\n\n\n\n<li>Add a new SSH key by pasting the copied content.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Step-3:-Add-Bitbucket's-SSH-Host-Key-to-Known-Hosts\">Step 3: Add Bitbucket&#8217;s SSH Host Key to Known Hosts<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Bitbucket&#8217;s SSH Host Key is added to Jenkins verification command <\/strong>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh-keyscan bitbucket.org &gt;&gt; ~\/.ssh\/known_hosts<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Step-4:-Test-SSH-Connection-to-Bitbucket\">Step 4: Test SSH Connection to Bitbucket<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Test SSH Connection<\/strong>:<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh -T git@bitbucket.org<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Step-5:-Add-SSH-Credentials-to-Jenkins\">Step 5: Add SSH Credentials to Jenkins<\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Open Jenkins<\/strong>: Go to your Jenkins URL and log in.<\/li>\n\n\n\n<li><strong>Manage Jenkins<\/strong>: Navigate to <code>Manage Jenkins<\/code> &gt; <code>Manage Credentials<\/code>.<\/li>\n\n\n\n<li><strong>Add SSH Key<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Select the system \u2192 Global credentials.<\/li>\n\n\n\n<li>Click on <code>Add Credentials<\/code>.<\/li>\n\n\n\n<li>Choose <code>SSH Username with private key<\/code>.<\/li>\n\n\n\n<li>Enter the following details:\n<ul class=\"wp-block-list\">\n<li><strong>Username<\/strong>: Your Bitbucket username.<\/li>\n\n\n\n<li><strong>Private Key<\/strong>: Select <code>Enter directly<\/code> and paste the contents of ~\/var\/lib\/jenkins\/.ssh\/id_rsa.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Choose  Create it will give you an ID (3opcasc-xxxx-xxxx-xxxx-xxxu9)<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/11\/image-2.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"873\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/11\/image-2-1024x873.png\" alt=\"\" class=\"wp-image-8368\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/11\/image-2-1024x873.png 1024w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/11\/image-2-300x256.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/11\/image-2-768x654.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/11\/image-2-1536x1309.png 1536w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/11\/image-2-352x300.png 352w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/11\/image-2.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Step-6:-Configure-Jenkins-Pipeline\">Step 6: Configure Jenkins Pipeline<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">example : <br>sample pipeline configuration to checkout git<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> stages {\n        stage('Checkout example Repository') {\n            steps {\n                git(\n                    branch: 'main',\n                    credentialsId: '37ef07ad-xxxx-xxxxx-xxxx-xxxx6709be',\n                    url: 'git@bitbucket.org:orange\/example.git'\n                )\n            }\n        }\n    }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction : Configuring Git credentials in Jenkins is essential for automating your build and deployment pipelines. By securely storing and [&hellip;]<\/p>\n","protected":false},"author":509,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1020],"tags":[],"class_list":["post-8344","post","type-post","status-publish","format-standard","hentry","category-containers-kubernetes","psol-cat-containers-kubernetes"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2aA","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/509"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8344"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8344\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}