Implementing Codacy's Pulse into bitbucket pipeline
Asked by Bradley Kirkland:

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


Answers:
author: Theodora Boudale
body: Hi [@Bradley Kirkland](/t5/user/viewprofilepage/user-id/4386945),

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](https://support.atlassian.com/bitbucket-cloud/docs/use-artifacts-in-steps/). 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

comments: author: Bradley Kirkland
body: 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


author: Theodora Boudale
body: 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


Tags: bitbucket-cloud

cloud