Showing posts with label Bitbucket. Show all posts
Showing posts with label Bitbucket. Show all posts

Tuesday, May 3, 2022

stderr: remote: Bitbucket Cloud recently stopped supporting account passwords for Git authentication. remote: App passwords are recommended | Fix for this issue | How to Create app passwords in Bitbucket?

When you are creating any freestyle jobs or pipeline jobs in Jenkins, when you try to checkout a project from Bitbucket and If you are using Bibucket password, you may get this error.

Reason for this error:

Beginning March 1, 2022, Bitbucket Cloud users will no longer be able to use their account passwords when using Basic authentication for Git over HTTPS and the Bitbucket Cloud REST API. The removal of account password usage for Basic authentication when using Git over HTTPS and/or the Bitbucket Cloud REST API is due to Bitbucket Cloud's ongoing effort to align with internal infrastructure and improve Atlassian account security. App passwords are substitute passwords for a user's account and are designed to be used for a single purpose with limited permissions.



How to Create App Passwords in Bitbucket?

Go to Bitbucket--> Settings
Click on App passwords --> Create app password



Now enter label name and click on read/write under repositories

Click on Create, this will generate app password.
Now you can this app password in Jenkins.

Thursday, September 19, 2019

Setup SSH Keys in BitBucket & Setup Java Web App in BitBucket

We will see how to setup Java Web App using Maven in BitBucket and also how to setup SSH keys in Bitbucket.

Pre-requisites:
If you don't have an bitbucket account, You need to create an account in bitbucket.org.
Implementation steps:

1. after login into bitbucket, click on + and Click on Create Repository


2. enter the repo name as MyBitbucketRepo, make sure it is private, Include read me option - choose yes with template. Click Git as version control system.
3. Click on create repository.
4. now click on your avatar (left bottom of the screen, BitBucket settings-> security--> ssh keys


5. now go to your laptop, open git bash for windows laptop or iTerm (for iMac laptop) and connect to Jenkins EC2 instance using Git bash. How to connect, refer this url - http://www.cidevops.com/2018/02/how-to-connect-to-ec2-instance-from.html
6. Now type  ssh-keygen (and then simply enter four times, do not give any password)


7. copy the content of public key executing below command in Gitbash.

sudo cat ~/.ssh/id_rsa.pub

8. go to click on Add key from step # 3,  and paste the content of public key. give some name as mySSH key. click on Add key.
9. Now click on repo you created in step # 1. Click on Clone and copy the SSH url. Do not select HTTPS Url. The url will be from your repo you created under Clone link. 
10. go back to Gitbash  windows connected to Jenkins EC2, execute the below command. Paste the SSH url you copied above.

git clone <ssh_url_from_bitbucket_repo_you_created>

   11. Now after cloning, type ls -al command
12. It will show a folder with repo name..
13. navigate to repo folder by below command:
    cd mybitbucketrepo
14. use below command to create Java project using Maven. Maven is the build for creating and building java projects.
mvn archetype:generate -DgroupId=com.mkyong -DartifactId=MyWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
15. type ls -al to see the new folder called MyWebApp
   16. type  below command to see the newly created project
git status



17. git add  *

18. Perform below command to commit the changes to local repository first.

git commit -m "my first project check-in to bitbucket"
19. Now perform below command to push from local repository to remote repository.

git push
Please watch here for live demo:



Wednesday, August 14, 2019

How to test SSH connection keys added in Bitbucket or GitHub?

How to test SSH connection keys added in Bitbucket or GitHub?

BitBucket
ssh -T git@bitbucket.org
logged in as <user_name>

You can use git or hg to connect to Bitbucket. Shell access is disabled

GitHub
ssh -T git@github.com
Hi <user-name>! You've successfully authenticated, but GitHub does not provide shell access.



Monday, August 12, 2019

What is Git? What is difference between Git and GitHub or Bitbucket?

Git is a open source, version control system, also known as SCM(source code management system) tool. It was founded by Linux Torvalds (founder of Linux OS).

Git is different from traditional version control systems such as SVN, CVS, etc. Git is distributed in nature which allows developers to have full history of their code repositories locally.

Git also has other features - branching, merging, pull requests, re-writing commit history.

Git is the most widely used version control system in the world today and is considered the modern standard for software development.

 BitBucket and GitHub are git based repositories hosted on internet or it could be hosted on-prem as well.

You need to have git client installed on your machine in order to access GitHub or BitBucket Repo.

To learn more about the difference between Git and other source version control systems, please click here.

Sunday, January 20, 2019

How to add SSH keys into Bitbucket from your machine? - Create SSH keys and upload into BitBucket

Let us see how to create SSH keys in your machine and upload into Bitbucket so that you can start checking code into Bitbucket.

Pre-requistes: 

Git installed on your machine by downloading from the below URL:
https://git-scm.com/downloads

Steps:
1. First create SSH keys by entering the below command.
ssh-keygen 
(and then simply enter four times, do not give any password)

2. the above command should create two keys - public keys and private keys.
copy the content of public key executing below command in Gitbash.
 
sudo cat ~/.ssh/id_rsa.pub

3. Now go to bitbuket.org
4. now click on your avatar (left bottom of the screen, and BitBucket settings-> security--> ssh keys
5. go to click on Add key,  and paste the content of public key. give some name as mySSH key. click on Add key.
6. Now click on repo you would like to check in or make code changes. Click on Clone and copy the SSH url. Do not select HTTPS Url. The url will be from your repo you created under Clone link.  

git clone <ssh_url_from_bitbucket_repo_you_created>  

7. That should create a folder in your machine. type ls -al
8. cd into repo name
9. Make code changes now

 

Wednesday, November 7, 2018

How to push a code change into Bitbucket remote repository? - Code push into Bitbucket using Git bash


Let us see how to push a code change using Git bash or iTerm on your local machine into bitbucket.

After configuring a freestyle job or pipeline using Jenkins for building and deployment, you would like to make a code change to make sure Jenkins have started automated builds/deployments.

Pre-requistes:
SSH keys set up and uploaded into Bitbucket.

Implementation steps:
1. Go to bitbucket, select repository which you already have setup MyWebApp.
If you already cloned, move to step # 6.
2. Click on clone
3. copy SSH clone url
4. go to git bash window
5. paste the url and enter
git clone git@bitbucket.org:username/repo_name.git
6. cd repo_name

change repo_name per your name of the repo you created in Bitbucket
7. cd MyWebApp/src/main/webapp
8. sudo vi index.jsp

Change Hello world into below yellow highlighted:
<html>
<body>
<h2>Howdy Folks !!! Welcome to DevOps!</h2>
</body>
</html>

9. press escape, enter :wq!
10. git add index.jsp
11. git commit -m "made change to jsp"
12. git push

Now refresh the browser and click on Source to see code changes you made in your git bash window.

Saturday, May 26, 2018

Migrate Java App from Bitbucket to Azure Cloud - How to migrate Java application to Azure Cloud from Bitbucket using VSTS

Let's say you have a Java application that is setup already in Bitbucket. Your organization have decided to migrate to Azure Cloud. Let us see how we can migrate the application to Azure:

Pre-requistes:
1. Java application set up in Bitbucket.
2. VSTS project setup.

Let us create WebApp in Azure Portal First. WebApp is a App service provide by Azure for hosting your web application. It supports .NET, Java, PHP,  Python and NodeJS. We will be deploying our Java Web App which is available in bitbucket repo.

Create App service on Azure portal
Now to login portal.azure.com
click on App services

Click on + Add
Click on Web App.
Create
Enter App service name(it should be unique)
Create a new resource group(for first time if you create an app service, otherwise you can use existing group name)

Select azure free subscription

Leave the rest default click save/create

This will take bit time to create the app service.
Now click on app service tab on left. You will see the newly created app service.
Select it, go to application settings. Choose Java 8 instead of .Net
And also web container as Tomcat.


Save and try to access the app service url by going to overview section of app service.

You should see the app service home page.

Steps to migrate java applications from Bitbucket to Azure Cloud using VSTS:

1. Login to VSTS. Click on your project.
2. Go to build and release
3. Click on builds
4. Click on New.
5. Select Bitbucket Cloud as Source. Select service connection.
6. Select use Username and password to authorize.
7. Click on three dots ... repository
8. Now choose a template by entering Java in the search textbook. Choose Azure WebApp for Java.
9. Click on Apply. VSTS already have Java Azure WebApp template.

10. Now Click on Maven pom.xml and make sure you have right goal - clean install
11. Leave the value as it is for Copy Files to staging folder

12. Publish Artifact: Drop 

13. Click on Stop azure web app
Enter Azure subscription.

Select Free trial subscription from the drop down.
14. Click on authorize(remove popup blocker)
15. do the same steps for Deploy Azure App and Start Azure App.
16. After done, click on Save and Queue.

Now you will see that VSTS would have started build.

After successful build, you can check the output by accessing below URL:

http://myAzureWebAppUrl/MyWebApp

Wednesday, March 21, 2018

How to add an existing project into bitbucket using command line ?

Let us say you have a project created along with source code. Now you would like to check-in the project into Bitbucket. How will you do it?

Pre-requistes:

1. Make sure Git is installed on that machine.
2. Make sure you add SSH keys to bitbucket.

1. Create a new repo in Bitbucket. Do not create README file yet.
2. Open git bash or command line terminal
3. navigate to your directory where you have source files.
4. run the below command to initialize the  directory as local repository.
       git init
5. Execute git add .
6. git commit -m "my project setup in bitbucket"
7. git remote add origin remote repository URL
8. git push -u origin master

Now login to Bitbucket and make sure code is available under Source tab for the repo.

Sunday, October 22, 2017

How to configure webhooks in Bitbucket to trigger a build in Jenkins? How to trigger automated builds in Jenkins through Bitbucket?

Jenkins jobs can be triggered many ways. Here are those ways:

1. pull - using poll scm
2. Webhooks (push mechanism) - by triggering a build from Bitbucket or GitHub for every repository changes.
3. through slack channel. Click here to learn about trigger Jenkins job using Slack.

Webhooks are triggers that enables developers to trigger Jenkins jobs automatically every time there is a code change.

we will see in this article how to trigger a(push) build for every change in bitbucket repository:

Changes needed in Jenkins

1. Click on Manage Jenkins.   
2. Click on Configure Global Security. 
3. Uncheck the option for Prevent Cross Site Request Forgery exploits
4. In matrix-based security change: 

for Anonymous user, do the below:

Overall - Read   
Job - Build  
Job - Read   

Job - Workspace



 
 
 
 
Select the job you would like to configure webhook is for. Choose configure Also you need to have token created for the job you would like to trigger. Click on the build job. Go to triggers section and click on Trigger builds remotely (e.g., from scripts)

 Authentication Token field. 
Also uncheck poll SCM option(if it was selected earlier) 















Changes in Bitbucket

1. go to bitbucket, choose the repository, go to settings, click on web hooks.



2. enter title, url which is your jenkins job url - append build/?token=myToken
 example the url should be like this - http://jenkins_public_dns_server_url:8080/job/myFirstAutomateJob/build?token=myToken

Sample url is given below:

http://jenkins_url:8080/job/myFirstAutomateJob/build?token=myToken

For e.g.,
jenkins public dns name - jenkins_url:8080
Freestyle job name -  myFirstAutomateJob
token= myToken
3. status should be active
4. click on skip certificate verification
5. triggers --> repository push

Now make a code change in bitbucket to see if that triggers a build in Jenkins automatically.