git commit to another repo is ignored

blaeser's Avatar

blaeser

25 Jul, 2018 10:02 AM

Hi all,

I am using Appveyor to commit a file back to another GitHub repository. Strangely, the "git commit" command is being ignored when I use some environment variables in the commit message. Here is a small example of what I am doing:

after_build:
  # this is all taken from https://www.appveyor.com/docs/how-to/git-push/
  - git config --global credential.helper store
  - ps: Add-Content "$HOME\.git-credentials" "https://$($env:access_token):x-oauth-basic@github.com`n"
  - git config --global user.email "[email blocked]"
  - git config --global user.name "Appveyor"
  - git clone -b some_branch --single-branch https://github.com/SomeRepo.git --depth 1
  - cd SomeRepo
  # copy the file that we want to commit
  - copy ..\somefile.xml .
  - git add . *.xml
  # now comes strange behavior: the following line is simply ignored. It does not show up in the log. Why? Is it the environment variables?
  - git commit -a --allow-empty -m "Appveyor commit: $($env:APPVEYOR_BUILD_NUMBER), $($env:APPVEYOR_BUILD_VERSION) based on $($env:APPVEYOR_REPO_COMMIT)"
  # this here actually works, but it lacks the important info, where the build is coming from
  - git commit -a --allow-empty -m "Appveyor commit"
  - git push

I also tried different variants of the environment variables in the commit message, such as $env:APPVEYOR_BUILD_NUMBER (same effect), $APPVEYOR_BUILD_NUMBER (same effect), %APPVEYOR_BUILD_NUMBER% (throws an error).

BR,
Max

  1. Support Staff 1 Posted by Ilya Finkelshte... on 25 Jul, 2018 10:39 AM

    Ilya Finkelshteyn's Avatar

    I assume you are running Windows build (not Linux one). So you call git commit in CMD mode (no prefix defaults to CMD on Windows builds). However environment variables are in PowerShell style. %APPVEYOR_BUILD_NUMBER% is correct option. Look at error it throws deeper, but first start using both variables (%APPVEYOR_BUILD_VERSION% too) in CMD style.

  2. 2 Posted by blaeser on 25 Jul, 2018 11:52 AM

    blaeser's Avatar

    Thanks for the response, yes, it is a Windows build. However if I use the line:

      - git commit -a --allow-empty -m "Appveyor commit: %APPVEYOR_BUILD_NUMBER%, %APPVEYOR_BUILD_VERSION% based on %APPVEYOR_REPO_COMMIT%"
    

    I am getting the following error:

    Error parsing appveyor.yml: (Line: 52, Col: 43, Idx: 1662) - (Line: 52, Col: 44, Idx: 1663): While scanning for the next token, find character that cannot start any token.
    
  3. Support Staff 3 Posted by Ilya Finkelshte... on 25 Jul, 2018 11:56 AM

    Ilya Finkelshteyn's Avatar

    Wrap the command in single quotes, e.g.

    - 'git commit -a --allow-empty -m "Appveyor commit: %APPVEYOR_BUILD_NUMBER%, %APPVEYOR_BUILD_VERSION% based on %APPVEYOR_REPO_COMMIT%"'
    

    You can always use UI and Export YAML button if you are not sure in syntax.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac