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

Pipeline branches Edited

I'm just getting started with Pipelines, and am trying to set one up that runs when commits are merged into our develop branch (the step/script stuff is already working when it's part of the default block; I just want to target specifically develop.)

I'm editing my bitbucket-pipelines.yml file in the online editor, and am getting a warning dot with error message when I use this config:

 

# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: php:7.1.1

pipelines:
branches:
develop:
- step:
name: Transition Jira ticket to done
script:
- pipe: atlassian/jira-transition:0.1.4
variables:
JIRA_BASE_URL: $JIRA_BASE_URL
JIRA_USER_EMAIL: $JIRA_USER_EMAIL
JIRA_API_TOKEN: $JIRA_API_TOKEN
ISSUE: $BITBUCKET_BRANCH
TRANSITION: "Done"

The error is occurring on the "branches" and "develop" lines; the branches error says "branches requires pattern to target specific branches", and the develop error says "Unexpected property develop".

Where am I going wrong here?

 

UPDATE: I did get the branch pipeline to save, using this code:

pipelines: 
default:
-
step:
script:
-
echo "This script runs on all branches that don't have any specific pipeline assigned in 'branches'."
branches:
develop:
-
step:
script:
-
pipe: atlassian/jira-transition:0.1.4
variables:
JIRA_BASE_URL: $JIRA_BASE_URL
JIRA_USER_EMAIL: $JIRA_USER_EMAIL
JIRA_API_TOKEN: $JIRA_API_TOKEN
ISSUE: $BITBUCKET_BRANCH
TRANSITION: "Done"

But now when I merge a commit to develop, the pipeline fails with this error:

String "develop" does not contain issueKeys

Cannot find issue key

1 answer

0 votes

Hi @Esther Strom

I'm glad that you could already fix the first part of the issue =]

Now the problem is on understanding how the PIPE jira-transitions works. According to what is described in the link before, the ISSUE attribute should receive a Jira issue key but it is receiving the name of the branch which will be always develop.

I guess the example you see for jira-transitions (where you use the variable $BITBUCKET_BRANCH) was designed to be used in the default section to capture branches created with a Jira key name.

If, for example, you are trying to transition an issue based on issue keys present in your commit messages, you will need to parse this data using a different command and create a new variable where the affected Jira issue is present. If this is your case, you would need something like:

JIRA_ISSUE=$(git log --pretty=format:%s -1 $BITBUCKET_COMMIT | grep -E -o '\<[A-Z][A-Z0-9]+\-[0-9]+\>' | head -1)

⚠️ Please keep in mind that this is just an example. You will need to adjust it to match your needs.


I hope that helps.

Thanks, @Daniel Santos

Just to make sure I understand, I can keep the develop branch and the predefined pipe; I just need to find another way to populate the ISSUE variable that's currently using $BITBUCKET_BRANCH?

Like Daniel Santos likes this

Yes, that is right! =]

OK. Again, keeping in mind this is my first-ever pipeline, I commented out the pipe and just tried to echo out the value of what the regex should return, but it's giving me a command not found error on "git". Do I need to somehow make sure that git is installed on the docker image?

2019-04-22_1546.png

(The regex does match what I'm looking for when I test it here against some of our ticket number formats (any number of letters, a dash, any number of numbers).

Hi @Esther Strom

Yes, you need to make sure git is installed so the command can succeed. You will need it to get the commit message.

I tested this command using the default docker machine atlassian provides when you don't specify a specific image.

Suggest an answer

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

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

4,450 views 4 22
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