Private repositories, GitHub & BitBucket (Get started with Jenkins, part 14)
- December 24, 2023
- Posted by: MainInstructor
- Category: Go
Video Title: Private repositories, GitHub & BitBucket (Get started with Jenkins, part 14)
Hey everyone my name is Xavier and in this video I’m going to show you how you can use Jenkins with private git repositories when you want to check out a private git repository that is hosted on github or bitbucket you need an SSH key to authenticate yourself that way
Github or bitbucket knows that you have permissions to access this repository so let’s take a look at how you can set up these keys in Jenkins so here I have a fresh installation of jenkins and i want to create a job that uses this bitbucket repository now it’s a private repository
So simply using this URL right here in my jobs configuration file will not work because bitbucket will prevent my Jenkins installation from reading anything from this repository so instead we need to generate an SSH key pair for our Jenkins installation so I’m going to open up my terminal and I’m already
Logged into my server that is running Jenkins and right now I am the root user on our system but our Jenkins installation actually runs under the Jenkins user if you have a default installation that will also be the case for you so I need to open up the
Terminal session for the Jenkins user so to do that I’m going to type sudo su Jenkins and then you notice that right now I am the Jenkins user now all that we have to do here is generate a new SSH key pair and to do that we just have to
Run ssh-keygen if I run that it will ask us where it should store our keys and I’m just going to leave the default pad as is and I’m not going to configure a passphrase so I’m going to leave that empty I’m going to leave the second one
Empty as well and then we can see that our key has been saved in that particular folder so now that we have our key we need to end bitbucket know that it should accept this key now to do that we need the contents of our public key file
I’m going to use cap here and there is the contents of our public key so I’m going to copy this all I’m going to go to bitbucket I’m going to go into the settings and I’m going to add this key as an access key an access key is in
Bitbucket or a bit special because they only have read-only access and that’s actually perfect because our Jenkins installation should not be able to make any commits it should only be able to check out our code so I’m going to add a key I’m going to give it a label I’m
Going to say that the label of this key is Jenkins I’m going to paste in the public key of my Jenkins installation the one we just generated don’t taste the private key in here that won’t work the private key has to remain private and only on your server we’re going to
Click on add key and that is it now good book it knows the key that belongs to our Jenkins server and it will allow it to read all of our source code that send this repository now before we can use it in a Jenkins job we also need to
Configure Jenkins to actually use this newly generated SSH key because right now it doesn’t know about it so I’m going to go to my Jenkins installation I’m going to manage Jenkins our whoops I mean credentials let’s go to credentials let’s open up the system systems credentials let’s go to global
Credentials and let’s add a new credential here I’m going to change the kind I’m going to set it to an ssh username with a private key you can give in any username you want to in the main mind Jenkins and then we can specify where our private key is so either we
Can enter it directly right here or we can pick any file on our server or we can use the default in the dot SSH directory so I’m going to leave it at this one at the last one into the default location for an SSH key I’m
Going to click OK and now Jenkins knows about our SSH key and we can use it inside of our jobs so let’s make a new job for our private repository I’m going to make it a freestyle project and I’m going to call it my project I’m going to click OK you can
Use an SSH key and other project types as well so you can use it inside a pipeline I’m going to scroll down I’m going to set my source code management system to get and now a task speed the repository URL so I’m going to go to bitbucket
I’m going to go to overview and here I have the SSH URL to my repository so when copy that and paste that in here and Jenkins gives us a warning because it’s not allowed to read from the remote repository it says please make sure you have the correct access right and that
Is because right now Jenkins is using no credentials so if I open up this drop down we can use the SSH key that we just entered in Jenkins so we click on that and our warnings should go away and there we go the warning is gone now I
Can save this job and let’s see if it all works let’s hit build now and after a few seconds you can see that our job has finished successfully I can open up the console output here and I can see that it has successfully fetched all of
Our code you can see also the latest commit message that this readme created online with bitbucket that was the commit that I created was very simple one and so now our Jenkins has access to our private repository now if you have a private github repository it’s about the
Same process except that they don’t call it access keys but they call it the blue keys so let’s go to get up here here I have a repository it’s not a private repository but let’s assume that it is you can go to settings and then in the
Deploy key section you can do the same thing as we’ve done with bitbucket you can add a new deploy key you can give it a title to call it Jenkins then you can paste in your key right here and then you can add it or you can even give it
Write access which is not really recommended for Jenkins but you can do it if you want to so that was it for this video I hope you find it interesting and if you did subscribe to my channel and check out the rest of my Jenkins tutorials thank you very much
For watching and I’ll see you in the next one you
-
Sale!
Wireless WIFI Repeater Extender Amplifier Booster 300Mbps
$29.99$14.99 Add to cartWireless WIFI Repeater Extender Amplifier Booster 300Mbps
Categories: Electronics, Wi-Fi Router, Wireless Wi-Fi Extender Tags: 300Mbps, 802.11N, Amplifier, Booster, Extender, mobile wi-fi booster, Remote, WIFI, Wireless, Wireless WIFI, Wireless WIFI Repeater, Wireless WIFI Repeater Extender, Wireless WIFI Repeater Extender Amplifier, Wireless WIFI Repeater Extender Amplifier Booster, Wireless WIFI Repeater Extender Amplifier Booster 300Mbps$29.99$14.99 -
Sale!
Full RGB Light Design Gaming Headset Headphones with Mic
$24.99$14.99 Add to cartFull RGB Light Design Gaming Headset Headphones with Mic
Categories: Electronics, Gaming, Gaming Headsets Tags: Design, Full, Full RGB Light Design Gaming Headset, Full RGB Light Design Gaming Headset Headphones, Full RGB Light Design Gaming Headset Headphones with Mic, Gamer, Gaming, Gaming Headset Headphones, gaming headset wireless, Headphone, Headphones, Headset, Light, Mic, Package, RGB$24.99$14.99 -
Sale!
Wireless BlueTooth Multi-Device Keyboard Mouse Combo
$39.99$19.99 Add to cartWireless BlueTooth Multi-Device Keyboard Mouse Combo
Categories: Electronics, Gaming, Gaming Keyboards, Keyboard Mouse Combos Tags: Combo, Keyboard, keyboard mouse combos, Mouse, MultiDevice, Set, WireKeyboard Mouse Combo, Wireless, Wireless BlueTooth Keyboard Mouse Combo, Wireless BlueTooth Keyboard Mouse Combos, Wireless BlueTooth Multi-Device Keyboard Mouse Combo, Wireless BlueTooth Multi-Device Keyboard Mouse Combos$39.99$19.99 -
Sale!
High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
$199.99$139.99 Add to cartHigh Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar
Categories: Gaming, Gaming Chairs Tags: Adjustable, Chair, computer chairs, Desk, Executive, Gaming, Girl, Headrest, High, High Back Leather Executive Adjustable Swivel Gaming Chair, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest, High Back Leather Executive Adjustable Swivel Gaming Chair with Headrest and Lumbar, High Back Leather Executive Adjustable Swivel Gaming Chairs, Leather, Lumbar, Office, Racing, Swivel$199.99$139.99 -
Sale!
Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
$29.99$19.99 Select optionsProfessional LED Light Wired Gaming Headphones with Noise Cancelling Microphone
SKU: N/A Categories: Electronics, Gaming, Gaming Headsets Tags: Cancelling, Gaming, Gaming Headphones with Noise Cancelling Microphone, gaming headset, Headphones, Headset, LED, Light, Mic, Microphone, Noise, Professional, Professional LED Light Wired Gaming Headphones, Professional LED Light Wired Gaming Headphones with Noise Cancelling Microphone, Wired, Wired Gaming Headphones, Wired Gaming Headphones with Noise Cancelling Microphone$29.99$19.99 -
Sale!
Gaming Desk with LED Lights USB Power Outlets and Charging Ports
$349.99$249.99 Select optionsGaming Desk with LED Lights USB Power Outlets and Charging Ports
SKU: N/A Categories: Computer Desk, Gaming, Gaming Desk Tags: and Charging Ports, Charging, Desk, Desks, Gaming, gaming desk with led lights, Gaming Desks with LED Lights, Home, LED, Lights, Monitor, Office, Outlets, Port, Power, Room, Stand, USB, USB Power Outlets, White, Workstation$349.99$249.99 -
Sale!
Wired Mixed Backlit Anti-Ghosting Gaming Keyboard
$99.99$79.99 Add to cartWired Mixed Backlit Anti-Ghosting Gaming Keyboard
Categories: Electronics, Gaming, Gaming Keyboards Tags: Antighosting, Backlit, Blue, brown, Gaming, Gaming Keyboard, gaming keyboards, gaming keyboards and mouse, Keyboard, Laptop, Switch, Wired, Wired Mixed Backlit Anti-Ghosting Gaming Keyboard, Wired Mixed Backlit Anti-Ghosting Gaming Keyboards, Wired Mixed Backlit Gaming Keyboard$99.99$79.99 -
Sale!
Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
$119.99$59.99 Add to cartWireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset
Categories: Electronics, Gaming, Gaming Headsets Tags: 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, ANC, Audio, Bluetooth, Cancellation, Ear, Earphone, gaming headset, Headphones, Headset, Hi-Res Over the Ear Headphones Headset, HiRes, Noise, Wireless, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Headphones, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headset, Wireless Bluetooth 5.3 ANC Noise Cancellation Hi-Res Over the Ear Headphones Headsets$119.99$59.99 -
Sale!
Wired Sports Gaming Headset Earbuds with Microphone
$19.99$9.99 Select optionsWired Sports Gaming Headset Earbuds with Microphone
SKU: N/A Categories: Gaming, Gaming Headsets Tags: Accessories, Earbud, Earphone, Earphones, Gaming, gaming headset with microphone, Headphones, Headset, IOS, Microphone, Sports, Wired, Wired Sports Gaming Headset Earbuds, Wired Sports Gaming Headset Earbuds with Microphone, Wired Sports Headset Earbuds$19.99$9.99 -
Sale!
150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
$49.99$29.99 Add to cart150W Universal Multi USB Fast Charger 16 Port MAX Charging Station
Categories: Charging Stations, Electronics Tags: 150W, 150W Charging Station, 150W Universal Multi USB Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Station, 150W Universal Multi USB Fast Charger 16 Port MAX Charging Stations, 150W Universal Multi USB MAX Charging Station, 16 Port MAX Charging Station, 3.5A, Charger, Charging, Fast, laptop charging stations, Max, Multi, Port, Stand, Station, Universal, USB$49.99$29.99
Thank you for that nicely done tutorial.
instead of jenkins user, can we create ssh keys with any other user .?
Watched a ton of different videos. Even use a Pluralsight subscription and no one could explain it as well and simply as you. Much appreciated.
Save a bunch of time and use blue ocean plugin…. also pointless to use freestyle project other than for demo purposes…the real power of jenkins lies in the pipelines
Hello, thank you for the great Video. I have one Problem. In run a VM for Jenkins and one VM for my Git Server. I don't have a Interface like GitHub oder Bitbucket. How can add the Key to my Git Repo?
Deploy Keys shouldn't have write access but webhooks can. why?
After I applied credentials still the error is not going
top man!!!!
Thanks you
Thank you so much. Such a helpful video.
please make a video about deploying from jenkins
SSH Credentials Plugin no longer supports SSH credentials from files on the Jenkins master file system, neither user-specified file paths nor ~/.ssh. Existing SSH credentials of these kinds are migrated to "directly entered" SSH credentials.
How do I log into Jenkins to get that ssh key? Can anyone help?
My Jenkins doesn't have the option 'From the Jenkins Master ~/.ssh', so I have entered the private key using 'Enter Private Key Directly' option. That didn't work. Could you please help ?
My warning is not going
Thanks a lot!
Hi there, May I please know how will it work on multiple private repositories?
Thanks <3
Great video! You just saved my day1
returned status code 128:
stdout:
stderr: remote: Invalid username or password.
Thank you for that nicely done tutorial.
Really a nice tutorial. How can I build multiple Bitbucket repositories with a single Jenkins job?