Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,301,420
Community Members
 
Community Events
165
Community Groups

Implementing Codacy's Pulse into bitbucket pipeline

I am wanting to implement a tool called pulse into my CI/CD which is bitbucket pipelines. I am required to do the following:

1) Use Bitbucket Pipelines script to figure out what are the new commits since the previous build (to the main branch)
2) Install Pulse CLI (the latest version is 1.9.4)
3) Use the Pulse CLI to push all new commits as changes
4) Use the Pulse CLI to push the new build as a deployment

These data points will allow us to analyze two metrics: Deployment Frequency, Lead time for changes.

To do this I have built the following script:
image: bitnami/git

pipelines:
branches: # matched against branches in your Git repository
staging: # branch name
- step:
name: Autodeploy staging
deployment: staging
script:
- apt-get update
- apt-get -qq install git-ftp
- git ftp push -v --user $stageUser --passwd $stagePass ftp.yetitech.nz

- step:
name: Manually deploy production
deployment: production
trigger: manual # manually trigger the deployment if the sync list in the previous step looks good
script:
- GET /2.0/repositories/{workspace}/{repo_slug}/pipelines/ # Get git tag version
- apt-get update
- apt-get -qq install git-ftp
- git ftp push --user $prodUser --passwd $prodPass ftp.yetitech.nz

- step:
name: install pulse
script:
- curl -fsSL -o pulse-event-cli https://artifacts.codacy.com/codacy/pulse/event-cli/1.9.4/pulse-event-cli_linux_amd64/pulse-event-cli && \
chmod +x pulse-event-cli

- step:
name: pulse
script:
- ./pulse-event-cli push git deployment \
- --api-key "QcWp63bs3oEqRtjmNqVF6jl3YYJhgLRg4L5VK2n3/Sro00NnaTTStA==" \
- --timestamp "$(date +%s)" \

I am having difficulty as it's erroring on the curl script. Can anyone please help guide me as to why this is happening? I'm also unsure if I'm performing the correct approach for grabbing the git version tags

1 answer

0 votes

Hi @Bradley Kirkland,

I attempted to execute the curl command from the yaml file you posted here and I also see an error, I suspect it may have to do with the command being multi-line. can you try modifying this command as follows?

- >
curl -fsSL -o pulse-event-cli https://artifacts.codacy.com/codacy/pulse/event-cli/1.9.4/pulse-event-cli_linux_amd64/pulse-event-cli &&
chmod +x pulse-event-cli

Please also note that files generated/downloaded in one step are not available in the next steps, unless they are defined as artifacts. For every step of your yaml file, a Docker container starts, the repo is cloned in that container and then the commands of the script are executed. When the step finishes, that Docker container gets destroyed and a new one starts for the next step.

If you download the file pulse-event-cli in the third step and you want to use it in the next step, you can define it as an artifact the following way:

- step:
name: install pulse
script:
- >
curl -fsSL -o pulse-event-cli https://artifacts.codacy.com/codacy/pulse/event-cli/1.9.4/pulse-event-cli_linux_amd64/pulse-event-cli &&
chmod +x pulse-event-cli
artifacts:
- pulse-event-cli

Another option would be to download the file in the same step that uses it (i.e. merge the 3rd and 4th steps into one).

You also mention that you are unsure about the approach for getting the git version tags. Are you referring to the following command from the second step?

- GET /2.0/repositories/{workspace}/{repo_slug}/pipelines/ # Get git tag version

It's a bit unclear what info you want to get, you mention git tags, but this endpoint lists all pipelines for a certain repo. Could you please share some more details on what information you need and are trying to get?

Kind regards,
Theodora

Hey Theodora, 

I feel creating a single step is the way to go: 

- step:
name: install pulse
script:
- >
curl -fsSL -o pulse-event-cli https://artifacts.codacy.com/codacy/pulse/event-cli/1.9.4/pulse-event-cli_linux_amd64/pulse-event-cli &&
chmod +x pulse-event-cli

- ./pulse-event-cli push git deployment \
- --api-key "QcWp63bs3oEqRtjmNqVF6jl3YYJhgLRg4L5VK2n3/Sro00NnaTTStA==" \
- --timestamp "$(date +%s)" \

However, this is giving me another multiline error on 

- --timestamp "$(date +%s)" \

I don't understand what to do to fix the multi-line issue.

 

Are you able to please help by explaining the fix?

 

The reason for requiring the git version tags is due to being used by Pulse to calculate some of the metrics, I can see I have muddled up the code

Hi Bradley,

Sure, I can explain. The commands in a script start with a dash (-) and a space

- step:
name: install pulse
script:
- command_1
- command_2

If you have a multiline command, you can

  • add the character > after the dash and space for this specific command
  • start the command at the next line with two spaces indentation
  • continue in the following lines with the same indentation, but omit the character \
- step:
name: install pulse
script:
- command_1
- >
command_2 argument_1
argument_2
argument_3 && command_3
- command_4

I believe that your example would look like follows:

- step:
name: install pulse
script:
- >
curl -fsSL -o pulse-event-cli https://artifacts.codacy.com/codacy/pulse/event-cli/1.9.4/pulse-event-cli_linux_amd64/pulse-event-cli &&
chmod +x pulse-event-cli
- >
./pulse-event-cli push git deployment
--api-key "QcWp63bs3oEqRtjmNqVF6jl3YYJhgLRg4L5VK2n3/Sro00NnaTTStA=="
--timestamp "$(date +%s)"

The part regarding git version tags is still a bit unclear to me. Are you trying to get the Git tag of the commit that the build is running for? Or all the git tags that exist in the repo? Or something different? Could you perhaps explain with an example?

Kind regards,
Theodora

Suggest an answer

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

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,265 views 2 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