Azure DevOps pipeline set git user email from build variable - azure-devops

When pipeline is triggered by committer "Teppo Tulppu" "teppo.tulppu#duckburg" user.name ends up as Teppo.
Is this an Azure DevOps "feature" or can I fix this somehow?
- task: Bash#3
displayName: 'Set git config email & name'
inputs:
targetType: 'inline'
script: |
git config --global user.email $BUILD_REQUESTEDFOREMAIL
git config --global user.name $BUILD_REQUESTEDFOR

This is not the Azure DevOps feature. This is some limits with git config command. If your username like "aa bb", and you input the command like git config --global user.name aa bb,user.name will only display letters which are before the space.
So you can change your script to below and then the user name will display as your expected.
git config --global user.email $BUILD_REQUESTEDFOREMAIL
git config --global user.name "$BUILD_REQUESTEDFOR"
Just use the specifal characters " to contain the predefined variable can fix this.

Related

error: pathspec 'main' did not match any file(s) known to git

I have a very simple Yaml code, I am trying to use and it is causing me so much pain but I cannot see an error besides the one i am getting at the end
error: pathspec 'main' did not match any file(s) known to git
[detached HEAD d1f4c36] Work now
Here is the code :
stages:
- stage : Build
jobs:
- job:
displayName: "Build Ripple 3 dataverse Solution"
pool :
vmImage: 'windows-2019'
variables:
- group: "Ripple 3 Core"
steps:
- task: PowerPlatformToolInstaller#2
inputs:
DefaultVersion: true
displayName : "Power Platform Tool Installer"
- task: PowerPlatformExportSolution#2
inputs:
authenticationType: 'PowerPlatformSPN'
PowerPlatformSPN: 'Service Connection'
SolutionName: '$(PowerPlatformSolution)'
SolutionOutputFile: '$(Pipeline.Workspace)\$(PowerPlatformSolution).zip'
- task: PowerPlatformUnpackSolution#2
inputs:
SolutionInputFile: '$(Pipeline.Workspace)\Ripple3Core.zip'
SolutionTargetFolder: '$(Build.SourcesDirectory)\$(PowerPlatformSolution)_unmanaged'
- script: |
git config user.email "xx#xx.com"
git config user.name "Automatic Build"
git checkout main
git add --all
git commit -m "Work now"
git push origin main
Try
git checkout "main"
Also, it may be necessary to checkout before exporting solution :
https://zupimages.net/viewer.php?id=22/40/z330.png
It is also possible to use Publish artifacts component :
https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml
Git is telling you that it does not recognize 'main' as branch nor file. The branches only exist on remote repository unless you checked them out already.
Instead of
git checkout main # there is no local branch called main
Try
git checkout origin/main
Try adding git fetch before your checkout.
git fetch
git checkout main

fatal: could not read Username for 'https://github.com': invalid url

I am trying to setup auto merge for my main branch whenever something is pushed into the development branch using gitaction. This is my gitaction file:
name: Auto merge
on:
push:
branches:
- development
env:
# replace "github_username" with your GitHub username
# replace "github.com/username/repo.git" with your GitHub repo path
# do NOT replace ${{secrets.GITHUB_TOKEN}}, GitHub will take care of it
MY_REPO: https://my-username:${{secrets.GITHUB_TOKEN}}#github.com/organisation-username/repo.git
# replace "long-lived_branch_name" with your branch name
MY_BRANCH: development
# replace it with the path to master repo
MAIN_REPO: https://github.com/organisation-username/repo.git
# replace "master" with your master branch name
MAIN_BRANCH: main
jobs:
merge:
runs-on: ubuntu-latest
steps:
- name: Merge with master
run: |
git clone ${{env.MY_REPO}} -b ${{env.MY_BRANCH}} tmp
cd tmp
git config user.name "Automerge Bot"
git config user.email "gcpabia#gmail.com"
git config pull.rebase false
git pull ${{env.MAIN_REPO}} ${{env.MAIN_BRANCH}}
git push
The thing is I belong to the organization as owner, so the repo isn't in my personal account. I keep getting this error:
Run git clone ***github.com/organization-username/repo.git -b development tmp
Cloning into 'tmp'...
fatal: could not read Username for 'https://github.com': No such device or address
Error: Process completed with exit code 1.
My suspicion is that the issues might be the different usernames I am using to carryout this operation and have switched between that of the organization and my personal account with no success.
Any pointers as to what I am missing.

AzureDevOps clone and commit external repo

I have a azure devops pipeline which checkout a github repo , i also want to have a bash task to checkout another repo and modify it , check it back in .
git clone https://$(githubApiKey)#mygithub.private.com/myrepo/ops-one-code.git
Error message:
fatal: could not read Password for 'https://***#mygithub.private.com':
terminal prompts disabled
Did you generate personal access token on GitHub?
Just create new token from the below page with needed scopes:
settings > developer settings > personal access tokens > generate new
token
Then use git clone command like below:
git clone https://auth-token-goes-here#mygithub.private.com/myrepo/ops-one-code.git
You can accomplish your requested task using two powershell tasks:
Task to checkout a Github repository:
- task: PowerShell#2
displayName: Checkout Repo
inputs:
targetType: 'inline'
script: |
git config user.email "user.email"
git config user.name "user.name"
Remove-Item s1 -Recurse -Force -ErrorAction Ignore
git clone https://username:$(PAT)#github.com/org/repo.git s1
cd s1
git checkout main
workingDirectory: '$(Pipeline.Workspace)'
Task to push back on the Github repository
- task: PowerShell#2
displayName: Push git changes
inputs:
targetType: 'inline'
script: |
git config user.email "user.email"
git config user.name "user.name"
git add --all
git commit -m "message"
git push https://username:$(PAT)#github.com/org/repo.git s1
workingDirectory: '$(Pipeline.Workspace)/s1'
Problem was the azure variable was a secret and it didn’t work with it hence it prompted for the password

Git on Azure self hosted agent pipelines

I am building an Azure pipeline for a GitHub web site to run on Windows Self-Hosted agents.
The default branch for the GitHub project is develop, all developers commit to this branch. I want a script that will merge develop to release for the time where a version is on tests and merge release to master once in production.
I'm new with git commands, I know the pipeline runs under a service account on the agent, behind a proxy and the pipeline impersonate somehow to another account to connect to GitHub.
To test my script, I logged onto the server as the service account and ran the following commands:
REM At start, the pipeline is on the develop branch so I move to release branch
C:\Agent\_work\29\s> git checkout release
>Updating files: 100% (928/928), done.
>Previous HEAD position was a62***: *comment*
>Switched to a new branch 'release'
>Branch 'release' set up to track remote branch 'release' from 'origin'.
C:\Agent\_work\29\s>git tag "branchTests"
C:\Agent\_work\29\s>git status
>On branch release
>Your branch is up to date with 'origin/release'.
>
>nothing to commit, working tree clean
REM I understood I had to first get the release branch and then pull the develop branch over it before pushing it all back
C:\Agent\_work\29\s>git pull origin develop
fatal: could not read Username for 'https://github.com': No such file or directory
C:\Agent\_work\29\s>git push --verbose --repo=release --set-upstream release
>Pushing to release
>fatal: 'release' does not appear to be a git repository
>fatal: Could not read from remote repository.
>
>Please make sure you have the correct access rights and the repository exists.
I have two questions:
Is my script correct in that context ?
Can this username error come from that I use the service account ? I should impersonate somehow as the same account the pipeline does ?
Thanks.
########## Update 1
I noticed that I don't need to add this if I don't disable the checkout in the pipeline
git config --global user.email "you#example.com"
git config --global user.name "xxx"
git remote set-url origin https://user:{GitHubPAT}#github.com/xxx/xxx.git
I have two files:
stages:
- stage: InitRelease
jobs:
- job: Branch
steps:
- checkout: self
clean: true
persistCredentials: true
- template: git-branch-source-2-target.yml#templates
parameters:
Tag: '${{ variables.projectName }}_${{ variables.buildId }}'
git-branch-source-2-target.yml
parameters:
- name: 'SourceBranch'
default: 'develop'
type: string
- name: 'TargetBranch'
default: 'release'
type: string
- name: 'Tag'
default: ''
type: string
steps:
- task: CmdLine#2
enabled: true
displayName: 'GIT Release'
inputs:
script: |
git checkout ${{parameters.SourceBranch}}
git pull origin
git checkout ${{parameters.TargetBranch}}
git pull origin
git tag ${{parameters.Tag}}
git push --tags
git merge ${{parameters.SourceBranch}}
git push origin --all --verbose
Thanks !
Run the following command in the cmd task of the pipeline:
git config --global user.email "you#example.com"
git config --global user.name "xxx"
git remote set-url origin https://user:{GitHubPAT}#github.com/xxx/xxx.git
git checkout develop
git pull origin
git checkout release
git merge develop
git push origin --all

Publish releases to gh-pages with travis without deleting previous releases

I want to publish releases to gh-pages. The deploy provider can be configured to keep history using keep-history: true. However I would like previous versions not to be just available in the git history but not to be deleted from the repository.
I've configured yarn and webpack to create a separate directory for each tag and to put the distribution in both a "latest"-directory as well as this tag specific directory. I would like to see a tag directory for all previous versions and not just for the latest version.
Here are the results of my current configuration: https://github.com/retog/rdfgraphnode-rdfext/tree/gh-pages
I found the following solution.
In travis.yml replace:
- provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN
keep-history: true
local-dir: distribution
on:
tags: true
With:
- provider: script
script: bash .travis_publish
on:
tags: true
And add the script file .travis_publish with the following content:
#!/bin/bash
PUBLICATION_BRANCH=gh-pages
# Checkout the branch
REPO_PATH=$PWD
pushd $HOME
git clone --branch=$PUBLICATION_BRANCH https://${GITHUB_TOKEN}#github.com/$TRAVIS_REPO_SLUG publish 2>&1 > /dev/null
cd publish
# Update pages
cp -r $REPO_PATH/distribution .
# Commit and push latest version
git add .
git config user.name "Travis"
git config user.email "travis#travis-ci.org"
git commit -m "Updated distribution."
git push -fq origin $PUBLICATION_BRANCH 2>&1 > /dev/null
popd