Having problem setting environment variables in appveyor with powershell

yosbeleg89's Avatar


08 Jun, 2017 02:58 PM

I have an script something like:


function conf
  Set-AppveyorBuildVariable "configuration" $config

echo "... env:APPVEYOR_REPO_TAG: $tag"
echo "... env:APPVEYOR_REPO_BRANCH: $branch"

if($tag -eq $true){
   conf "Production"
  conf "Testing"

But appveyor is throwing an error saying that the cmdlet Set-AppveyorBuildVariable is not recognized, I modified a bit to pass to it directly the value "Testing" and the same result is thrown:

Set-AppveyorBuildVariable : The term 'Set-AppveyorBuildVariable' is not recognized as the name of a cmdlet, function, 
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is 
correct and try again.
At C:\projects\onehack\setup-config.ps1:4 char:5
+     Set-AppveyorBuildVariable "configuration" "Testing"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-AppveyorBuildVariable:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

This was working with the os: Visual Studio 2015 but after we switched to os: Visual Studio 2017 it is not working anymore. Is there something I need to configure? Please any help here would be appreciated.

  1. Support Staff 1 Posted by Feodor Fitsner on 08 Jun, 2017 04:54 PM

    Feodor Fitsner's Avatar

    We'll fix that in the update coming this week.

    For now, explicitly load AppVeyor module with:

    import-module 'C:\Program Files\AppVeyor\BuildAgent\Modules\build-worker-api'
  2. 2 Posted by yosbeleg89 on 08 Jun, 2017 06:06 PM

    yosbeleg89's Avatar

    Great, this worked for me. Thank you very much!!!

  3. 3 Posted by yosbeleg89 on 08 Jun, 2017 08:12 PM

    yosbeleg89's Avatar

    Hmm, I have a question: When I set the configuration throw powershell msbuild is building the project with the Testing build configuration but it is applying the Debug transformation to the web.config, but if I set configuration: Testing to appveyor.yml everything is working as expected. Any ideas?

  4. Support Staff 4 Posted by Ilya Finkelshte... on 08 Jun, 2017 08:35 PM

    Ilya Finkelshteyn's Avatar

    If I understand you correctly, you have publish_wap: true in your YAML and transformation in generated WAP package does not respect configuration environment variable you set? I afraid this is how our WAP packaging implemented now, it looks only for project build configuration when constructing msbuild command. Could you please explain your scenario and why you need to set configuration using environment variable? We will try to find workaround for you.

  5. 5 Posted by yosbeleg89 on 08 Jun, 2017 08:50 PM

    yosbeleg89's Avatar

    Yes, I have publish_wap: true in the YAML, the transformation does not respect the configuration environment. I have an script the decides where it should build production or testing configurations before deploying to the production or testing servers depending if the commit is from master or a specific branch, very similar to the example of the original issue:

    Import-Module 'C:\Program Files\AppVeyor\BuildAgent\Modules\build-worker-api'

    $branch = $env:APPVEYOR_REPO_BRANCH

    function conf { param($config) Set-AppveyorBuildVariable "configuration" $config }

    echo "... env:APPVEYOR_REPO_BRANCH: $branch"

    if($branch -eq "testing-branch"){ conf "Testing" } else{ conf "Release" }

    So, if it is the testing-branch the Testing configuration is set and the project is built with the Testing build configuration but the Web.Testing.config transformation is not applied instead the Web.Debug.config one is applied.

  6. Support Staff 6 Posted by Ilya Finkelshte... on 08 Jun, 2017 08:52 PM

    Ilya Finkelshteyn's Avatar

    May be you can simple use per branch configuration?

  7. 7 Posted by yosbeleg89 on 08 Jun, 2017 09:47 PM

    yosbeleg89's Avatar

    Ok, it took me a while to achieve the whole transformation but I think I did now per branch configuration and it seems to be working. Thanks again for the help!.

  8. 8 Posted by yosbeleg89 on 08 Jun, 2017 09:51 PM

    yosbeleg89's Avatar

    The only think I did not liked is that I needed to put a lot a duplicated configurations per branch, is there a way to put all that only once?

  9. Support Staff 9 Posted by Ilya Finkelshte... on 08 Jun, 2017 11:42 PM

    Ilya Finkelshteyn's Avatar

    Agree, we don't like this too. We have this feature request which we need to implement.

  10. 10 Posted by yosbeleg89 on 09 Jun, 2017 02:12 PM

    yosbeleg89's Avatar

    Great!, Thanks

  11. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:17 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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