Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get the hash of the last commit or create a new empty commit using a bitbucket API Edited

Hello people, my question now is: I created a * sh to create a tag in another repository (weird thing I need more for my business rule to work in gcp) I'm doing this via the bitbucket api, only to create the precise hash tag for a commit from this repository, so far ok! But what I did is working, but of course it's not done well, but that's what I got for now.

#!/usr/bin/env bash

# Exit immediately if a any command exits with a non-zero status
set -e

# Set variables
REPOSITORY=$1
echo "Get Last Commit"
curl https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$REPOSITORY/commits/?pagelen=1 \  
-u 
$BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD_MASTER \
sed 's/{"pagelen.*, "hash//' arq1.hash > arq2.hash
grep -i "" arq2.hash | awk '{print $2}' > arq3.hash
sed 's/"//g' arq3.hash > arq4.hash
sed 's/,//g' arq4.hash > arq5.hash
LAST_COMMIT_HASH=$(cat arq5.hash)
rm -f arq*.hash
echo "Last Commit: " $LAST_COMMIT_HASH

# Create new tag
echo "Creating Tag"
curl (-)X POST https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$REPOSITORY/refs/tags \
(-u $BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD_MASTER \
--fail --show-error --silent \
-H 'Content-Type: application/json' \  
-d 
'{      
"name": 
"release_
'$BITBUCKET_BUILD_NUMBER'",
        "target": { 
               "hash": "
'$LAST_COMMIT_HASH'"
      }
  }'

What I would like to know is if it is possible through the API to rescue the hash of the last commit from the master of a repository OR if I can create an empty commit (git commit --allow-empty) through the api and in return get this hash? !

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

2,589 views 1 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you