Meta runner parameters

Answered

I am having trouble understanding how parameters can work within metarunners.

Given the following example where an exe name is specified, the full path is resolved by powershell from the working dir, how can this then be passed to the second runner?
Updating the param via setParameter does not work

<?xml version="1.0" encoding="UTF-8"?> <meta-runner name="Test">   <description>ParamTest</description>   <settings>     <parameters>     <param name="mr.executable" value="some.exe" spec="text description='The executable' display='normal' label='Executable'" />     </parameters>     <build-runners>       <runner name="Runner1" type="jetbrains_powershell">         <parameters>           <param name="jetbrains_powershell_execution" value="PS1" />           <param name="jetbrains_powershell_noprofile" value="true" />           <param name="jetbrains_powershell_errorToError" value="error" />           <param name="jetbrains_powershell_script_mode" value="CODE" />           <param name="jetbrains_powershell_bitness" value="x86" />           <param name="teamcity.step.mode" value="default" />           <param name="jetbrains_powershell_script_code"><![CDATA[[CmdletBinding()] Param (     [string] $workingDir = "%teamcity.build.workingDir%",        [string] $ExeName = "%mr.executable%", )      $exe = Join-Path $workingDir "\*\$ExeName" | Resolve-Path   Write-Host "##teamcity[setParameter name='mr.executable' value='$exe']" ]]></param>         </parameters>       </runner>       <runner name="Run exe" type="jetbrains.dotNetGenericRunner">         <parameters>           <param name="proc_bit" value="MSIL" />           <param name="proc_path">%mr.executable%</param>           <param name="proc_runtime_version" value="v4.0" />           <param name="teamcity.step.mode" value="default" />         </parameters>       </runner>     </build-runners>     <requirements />   </settings> </meta-runner>

,

0
20 comments

Did you try to create a build configuration from this meta runner and check whether it works?

0

Yes I did, it does not pass the updated variable value to the second runner, presumably as it is evaluated when the metarunner is loaded rather than when it is called and the powershell runs after this has happened.

[EDIT] I should add that the above sample has a typo or two, my real metarunner is doing lots more but the quickly hacky sample above captures the essence of the issue I'm having. It does run correctly and no matter what I've tried, I cannot update the final runner's param value in any previous runner within the same metarunner

0

Maybe the problem is in powershell line:
Write-Host ##teamcity[setParameter name='mr.executable' value='$exe']"

I see closing quote, but I don't see the quote in the beginning. Shouldn't it be:
Write-Host "##teamcity[setParameter name='mr.executable' value='$exe']"
?

0

see above edit, my value is being correctly set with correct quotes in log

<?xml version="1.0" encoding="UTF-8"?>
<meta-runner name="Test">
  <description>ParamTest</description>
  <settings>
    <parameters>
    <param name="mr.executable" value="some.exe" spec="text description='The executable' display='normal' label='Executable'" />
    </parameters>
    <build-runners>
      <runner name="Runner1" type="jetbrains_powershell">
        <parameters>
          <param name="jetbrains_powershell_execution" value="PS1" />
          <param name="jetbrains_powershell_noprofile" value="true" />
          <param name="jetbrains_powershell_errorToError" value="error" />
          <param name="jetbrains_powershell_script_mode" value="CODE" />
          <param name="jetbrains_powershell_bitness" value="x86" />
          <param name="teamcity.step.mode" value="default" />
          <param name="jetbrains_powershell_script_code"><![CDATA[[CmdletBinding()]
Param (
    [string] $workingDir = "%teamcity.build.workingDir%",
       [string] $ExeName = "%mr.executable%",
)

     $exe = Join-Path $workingDir "\*\$ExeName" | Resolve-Path
  Write-Host "##teamcity[setParameter name='mr.executable' value='$exe']"

]]></param>
        </parameters>
      </runner>
      <runner name="Run exe" type="jetbrains.dotNetGenericRunner">
        <parameters>
          <param name="proc_bit" value="MSIL" />
          <param name="proc_path">%mr.executable%</param>
          <param name="proc_runtime_version" value="v4.0" />
          <param name="teamcity.step.mode" value="default" />
        </parameters>
      </runner>
    </build-runners>
    <requirements />
  </settings>
</meta-runner>


Updated to fix missing quote

0

Ok I meant double quotes, I still do not see a double quote before ##teamcity.

0

fixed typo in hacky sample, still does not work though

0

Just tried similar setup with two command line runners: one outputs parameter using setParameter and another one uses this parameter as path to executable. It works just fine.
You should see actual value for mr.executable parameter on tab Parameters of the build.

0

does it modify the original mr.executable parameter or create a new one?

0

In my case I had parameter defined in build configuration and first step changed it.

0

Can you post metarunner xml?

0

Sure:

<?xml version="1.0" encoding="UTF-8"?>
<meta-runner name="Set Parameter Sample">
  <description>Set parameter sample</description>
  <settings>
    <parameters>
      <param name="cmd" value="" />
    </parameters>
    <build-runners>
      <runner name="" type="simpleRunner">
        <parameters>
          <param name="script.content" value="echo &quot;##teamcity[setParameter name='cmd' value='dir']&quot;" />
          <param name="teamcity.step.mode" value="default" />
          <param name="use.custom.script" value="true" />
        </parameters>
      </runner>
      <runner name="" type="simpleRunner">
        <parameters>
          <param name="command.executable" value="%cmd%" />
          <param name="teamcity.step.mode" value="default" />
        </parameters>
      </runner>
    </build-runners>
    <requirements />
  </settings>
</meta-runner>

0

I can't see this working, the param is set to 'a' in the build step, updated in the first meta runner to 'dir' and passed to the second runner as 'a', not the updated value 'dir'. Using 9.0.4 (build 32407)

[15:45:13]Skip checking for changes - there are no VCS roots defined
[15:45:13]Clearing temporary directory: C:\BuildAgent\temp\buildTmp
[15:45:13]Publishing internal artifacts
[15:45:13][Publishing internal artifacts] Sending using WebPublisher
[15:45:13][Publishing internal artifacts] Sending using ArtifactsCachePublisher
[15:45:13]Checkout directory: C:\BuildAgent\work\3190862da085dfbe
[15:45:13]Step 1/1: One (Set Parameter Sample)
[15:45:13][Step 1/1] Step 1/2: Command Line
[15:45:13][Step 1/2] Starting: C:\BuildAgent\temp\agentTmp\custom_script6528178362987522774.cmd
[15:45:13][Step 1/2] in directory: C:\BuildAgent\work\3190862da085dfbe
[15:45:13][Step 1/2] "
[15:45:13][Step 1/2] ##teamcity[setParameter name='cmd' value='dir']
[15:45:13][Step 1/2] "
[15:45:13][Step 1/2] Process exited with code 0
[15:45:13][Step 1/1] Step 2/2: Command Line
[15:45:13][Step 2/2] Starting: C:\Windows\system32\cmd.exe /c a
[15:45:13][Step 2/2] in directory: C:\BuildAgent\work\3190862da085dfbe
[15:45:13][Step 2/2] 'a' is not recognized as an internal or external command,
[15:45:13][Step 2/2] operable program or batch file.
[15:45:13][Step 2/2] Process exited with code 1
[15:45:14][Step 2/2] Step Command Line failed
[15:45:14]Publishing internal artifacts
[15:45:14][Publishing internal artifacts] Sending using WebPublisher
[15:45:14][Publishing internal artifacts] Sending using ArtifactsCachePublisher
[15:45:14]Build finished
0

What version of TeamCity do you use?

0

Using 9.0.4 (build 32407)
cut and paste your exact xml into metarunner with single build config, with single step, running said meta runner. It fails to update param. Anything I should turn on for extra log info?

0

Ok, so it works in build configuration but does not work in meta runner. I reproduced it locally and I found similar issue in our tracker: https://youtrack.jetbrains.com/issue/TW-35383
Please watch for it.

0

Thanks, can this issue be marked as verified then as you and I can both reproduce it.
Also just noticed that this was raised on 01 Mar 2014 and has had 0 progress in that time. Should I expect this never to get fixed?

0

In issue tracker? We use this field when issue is fixed and verified by qa.

0

Landed on this problem when trying to make a half decent metarunner and noticed I couldn't pass arguments between two scripts.

This problem was initiated in 2015 and is still not fixed?

0

Harald S Hanssen Hi, I can see the sample meta-runner Pavel provided above working on 2022.2.2 after a minor edit (see the snippet below) and setting the build configuration parameter cmd value to %cmd% in build configuration settings > Parameters. Can you try that meta-runner for troubleshooting reasons or share your meta-runner?

<?xml version="1.0" encoding="UTF-8"?>
<meta-runner name="Set Parameter Sample">
  <description>Set parameter sample</description>
  <settings>
    <parameters>
      <param name="cmd" value="%cmd%" />
    </parameters>
    <build-runners>
      <runner name="" type="simpleRunner">
        <parameters>
          <param name="script.content" value="echo &quot;##teamcity[setParameter name='cmd' value='dir']&quot;" />
          <param name="teamcity.step.mode" value="default" />
          <param name="use.custom.script" value="true" />
        </parameters>
      </runner>
      <runner name="" type="simpleRunner">
        <parameters>
          <param name="command.executable" value="%cmd%" />
          <param name="teamcity.step.mode" value="default" />
        </parameters>
      </runner>
    </build-runners>
    <requirements />
  </settings>
</meta-runner>
0

Cool I'll look into it :)

Have to clear a bit of time to test it out.

0

Please sign in to leave a comment.