huserben / TfsExtensions

Extensions for TFS 2015+ such as custom Widgets (require TFS 2017) and Build Tasks
MIT License
45 stars 22 forks source link

Build parameters are being set as variables #142

Closed pedrolamas closed 3 years ago

pedrolamas commented 4 years ago

I have a pipeline where I'm using template parameters, like on this example:

parameters:
  - name: environment
    type: string
    displayName: Environment
    default: 'dev'
    values:
      - 'dev'
      - 'qa'
      - 'prod'

steps:
  - script: echo ${{ parameters.environment }}

If I manually trigger the above pipeline, I will get an option to specify the Environment parameter:

image

This is what it shows when I run the pipeline and select "qa" as environment:

image

So I assumed that the "buildParameters" would work with the above, so I wrote the task like this:

- task: TriggerBuild@3
  displayName: Trigger e2e testing
  inputs:
    definitionIsInCurrentTeamProject: true
    buildDefinition: 'other-build'
    queueBuildForUserThatTriggeredBuild: true
    ignoreSslCertificateErrors: false
    useSameSourceVersion: false
    useSameBranch: false
    waitForQueuedBuildsToFinish: true
    waitForQueuedBuildsToFinishRefreshTime: '10'
    failTaskIfBuildsNotSuccessful: true
    cancelBuildsIfAnyFails: false
    treatPartiallySucceededBuildAsSuccessful: false
    downloadBuildArtifacts: false
    storeInEnvironmentVariable: false
    authenticationMethod: 'OAuth Token'
    password: '$(System.AccessToken)'
    enableBuildInQueueCondition: false
    dependentOnSuccessfulBuildCondition: false
    dependentOnFailedBuildCondition: false
    checkbuildsoncurrentbranch: false
    failTaskIfConditionsAreNotFulfilled: false
    buildParameters: 'environment: qa'

Problem is that from what I can see, all this does is create a variable called "environment" on the child pipeline, not actually passing a build parameter:

image

Am I missing something here?

huserben commented 4 years ago

Hi @PedroLamas

thanks for raising this issue. If I understand correctly this is the same issue as #138 where also a workaround was provided.

So what is supported by the task are "Variables" that are settable at queue time (interally called buildparameters) but not "Runtime Parameters".

If it is the same problem as issue 138 then you would need to go for a workaround, as I currently have not planned to add support for those kind of parameters in the TriggerBuildTask.

Please let me know whether the issue was the same and you could work around it of its a different problem.

pedrolamas commented 4 years ago

Yes, reading through the other issue it does seem to be the same thing.

I will apply a workaround for this but maybe this is something that should be added to the docs as I suspect others will be reporting the same?

Also, would you be interested if I take a look and try to add this in and submit a PR for it?

huserben commented 4 years ago

Yes it should definelty go to the docs - I have a few things for documentation pending already:

Ideally I find time for those things and this problem to be documented properly in the next days.

Regarding the extended functionality, first of all thanks for the offer, very appreciated. I guess what could be done for sure is:

I think once these things are clarified the implementation wouldn't be too hard. Of course feel free to knock yourself out ont that as well. The problem at the moment is that for updating the calls to the REST API we will need to change https://github.com/huserben/TfsRestService as I put all the rest calls in this npm package (for easy reuse across the tasks and easy testability). This makes the implementation a bit more complex than it looks on first glance. But of course I would assist in case of questions

mohak2006 commented 4 years ago

I am facing same problem in my case. Is there any work going on regarding this?

huserben commented 4 years ago

Hi @mohak2006

sorry to disappoint, but currently I'm too busy on other things so I cannot do much more than give basic support here via the issues. But no further development is planned on my side at the moment.

jason-ha commented 4 years ago

Parameters to pipelines like template parameters were added in the last several months. These are documented as Runtime Parameters, which is a bit of an unfortunate name as one key advantage is expansion time resolution. Variables cannot be guaranteed resolvable until runtime and don't some with type-safety. So these "runtime" parameters should be handled differently than the current buildParameters. The current name is a little unfortunate as buildParameters is used to specify pipeline variables, but so goes the naming of things.

huserben commented 3 years ago

@jason-ha @pedrolamas @mohak2006

A new version of the task is now available that supports template parameters. Please let me know whether this solves your problems and whether it works as expected or not.

Thanks everyone for contributing, your help is appreciated!