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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,466,100
Community Members
 
Community Events
176
Community Groups

Unable to apply a tag to branch from Bitbucket pipeline

Edited

I have a self hosted runner running on Windows. I have a step in my pipeline to create a label and tag the current branch with that label.

I looked at long thread in this community that it should work. But it is not working.

 

The step is here:

- step:
  name: 'Tag the repo with build label'
  runs-on:
    - 'self.hosted'
    - 'windows'
    - 'aio'
  script:
    - echo "Tagging repo with label"
    if ( $Env:BITBUCKET_BRANCH -match "feature/*" )
    {
      ${BRANCH_PART} = "integration";
    }
    elseif ( $Env:BITBUCKET_BRANCH -match "release/*" )
    {
      ${BRANCH_PART} = "release";
    };
    ${RELEASE_CODENAME}="chicago";
    ${REPO_TAG} = "${BRANCH_PART}_${RELEASE_CODENAME}_$Env:BITBUCKET_BUILD_NUMBER";
  git tag -am "Tagging for build $Env:BITBUCKET_BUILD_NUMBER" "${REPO_TAG}";
    git remote set-url origin "$Env:BITBUCKET_GIT_HTTP_ORIGIN";
    git push --dry-run;
    echo git push origin "${REPO_TAG}";

I understand the script doesn't look like Bash script. It is because Windows runners run with Powershell as the parent shell. All those script lines are proper powershell script code.

The error I am seeing is this:

bash: /dev/tty: No such device or address

error: failed to execute prompt script (exit code 1)

fatal: could not read Username for 'https://bitbucket.org': No such file or directory

git

push

origin

integration_chicago_33

 

 

1 answer

0 votes
Patrik S Atlassian Team Jun 30, 2022

Hello @Video Guy ,

Thank you for reaching out to Atlassian Community!

This error is happening because the environment variable BITBUCKET_GIT_HTTP_ORIGIN you are currently using just contains the URL of the origin (such as http://bitbucket.org/<workspace>/<repo> ) but it does not contain any credentials for the authentication, so PowerShell is probably opening a pop up for you to provide the username and app password, and when you close this window it's failing with the error you shared.

That said, if you want to push back to your repository when using windows runners, you will need to provide the credentials for authentication (bitbucket username and app password) when setting the URL for origin. This can be done by creating environment variables either in the workspace or repository level, that contain these credentials. When creating those variables you can also mark them as Secured, so their value will be masked from the logs.

I went ahead and did some testing in my repository, and was able to get the tag push working with the following code : 

- step:

        name: 'Push a tag to the repository'

        runs-on: 

         - 'self.hosted'

         - 'windows'

        script:

          - echo "Tagging repo with label";

            $Env:BRANCH_PART = "master";

            $Env:RELEASE_CODENAME="chicago";

            $Env:REPO_TAG = "$($Env:BRANCH_PART)_$($Env:RELEASE_CODENAME)_$($Env:BITBUCKET_BUILD_NUMBER)";

            git remote set-url origin "https://$($Env:BB_USERNAME):$($Env:BB_APP_PASSWORD)@bitbucket.org/$Env:BITBUCKET_WORKSPACE/$Env:BITBUCKET_REPO_SLUG.git";

            git tag -a "$Env:REPO_TAG" -m "Tagging for build $Env:BITBUCKET_BUILD_NUMBER";

            git push origin $Env:REPO_TAG;

You can see in the example that we are using two custom variables, BB_USERNAME and BB_APP_PASSWORD, when configuring the repo's origin URL, and these variables were created at the repository level.

You can adapt the code above with your if/else statement and your own credentials and check how it goes.

Hope that helps! Let me know in case you have any questions.

Thank you, @Video Guy !

Kinds regards,

Patrik S

Then how is Bitbucket runner able to clone the workspace in the first place?

When I look at runner build step logs, this is what I see.

 

++++++++

+ $env:GIT_LFS_SKIP_SMUDGE = '1'; git clone --branch='feature/chicago' --depth 50 "https://x-token-auth:$Env:REPOSITORY_OAUTH_ACCESS_TOKEN@Bitbucket.org/$env:BITBUCKET_REPO_FULL_NAME.git" $env:BUILD_DIR
Cloning into 'C:\Users\cicdagent\atlassian-bitbucket-pipelines-runner\bin\..\builds\567e7a5d-0d86-52fc-a792-943bf82212a1\1656365456588\build'...
+ git reset --hard 37ee556d5888c8c5013811bc989511ec6436f6f6
HEAD is now at 37ee556 Added Launch4J config file
+ git config user.name bitbucket-pipelines
+ git config user.email commits-noreply@bitbucket.org
+ git config push.default current
+ git remote set-url origin https://bitbucket.org/$env:BITBUCKET_REPO_FULL_NAME.git
+ git reflog expire --expire=all --all

++++++++++++++++

The runner has baked the creds in when it cloned the repo. As I am doing a push from the same folder, why do I need to pass them again?

 

How can I make use of "x-token-auth:$Env:REPOSITORY_OAUTH_ACCESS_TOKEN" if I were to include it URL?

When I dumped environment vars, I don't see this var in the dump.

Patrik S Atlassian Team Jul 07, 2022

Hello @Video Guy ,

The token variable is used by the runner's own scripts to clone the repository but is currently not available to be referenced in the user's pipeline script, so this is the reason you can't see this variable when you print all the env variables in your script.

I'm afraid that currently if you want to push back to the repository when using Windows Runners, you would need to manually set the credentials for authentication as the example I shared in my previous response.

However, I went ahead and opened a feature request to implement the functionality you are looking for : 

I would suggest you to add your vote there, since this helps both developers and product managers to understand the interest. Also, make sure you add yourself as a watcher in case you want to receive first-hand updates from that ticket. Please note that all features are implemented with this policy in mind.

Thank you, @Video Guy .

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events