HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Pushing code changes from Pipeline back to repo/branch, using Git!

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
branchbackchangesusinggitcodefrompipelinepushingrepo

Problem

Here is the scenario: We are trying to "automate" our Salesforce development with Azure Pipelines. Since Salesforce is very unique when it comes to deploying changes, I have tried to create a Pipeline that would be manually run to save any change made into a Salesforce Sandbox back to a Branch.
The goal is to eventually merge these changes into other branches and deploy them into other Salesforce environments.

We are using the the SFDX cli for such tasks within the image. Below is a copy of my yml file:

trigger:
- developer

pool:
  vmImage: 'ubuntu-latest'

variables:
- group: DeveloperVariables

steps:
- checkout: self
  persistCredentials: true

- task: DownloadSecureFile@1
  inputs:
    secureFile: server.key
- task: Bash@3
  inputs:
    workingDirectory: ''
    targetType: inline
    script: |
      wget https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz;
      mkdir sfdx;
      tar xJf sfdx-linux-amd64.tar.xz -C sfdx --strip-components 1;
      sudo ./sfdx/install;
      sfdx force:auth:jwt:grant --clientid $CONSUMER_KEY --jwtkeyfile $DOWNLOADSECUREFILE_SECUREFILEPATH --username $USERNAME --setalias developer;
      sfdx force:mdapi:retrieve -u $USERNAME -k src/package.xml -r .;
      unzip unpackaged.zip;
      cd unpackaged;
      git config --global user.email "test@test.com"
      git config --global user.name "Test User"
      git checkout -t origin/developer;
      git add .;
      git status;
      echo "This is me: ";
      whoami;
      git commit -m "Retrieved latest Developer SB changes!"
      echo "Pushing now!!!";
      git push --set-upstream origin HEAD:developer;


As per Microsoft's documentation found here, we need to make sure we grant permissions to the build service. All the permissions have been granted as requested but we still can't get it to work.

Below is the copy of the logs generated when we run the Pipeline:

```
##[section]Starting: Bash
=======================================================

Solution

Found the issue...

The documentation states that the "contribute" permission needs to be added to "Project Collection Build Service Accounts".
There is also an USER called ""Project Collection Build Service".
After explicitly adding the "Project Collection Build Service" user to be able to contribute it worked as expected!

Context

StackExchange DevOps Q#8886, answer score: 3

Revisions (0)

No revisions yet.