2

I am having batch file called Formalbuild.bat ,It will take parameter name called componentName.

For ex. I will build the different components like below.

    Formalbuild.bat ServiceComponent
    Formalbuild.bat DatamodelComponent
    Formalbuild.bat 
                ...
                ...
    Formalbuild.bat SomeXYZComponent

Is it possible to create array of component name and pass one by one component to batch file to do build?

3 Answers 3

4

As only the component name changes, you could use a for loop or even better a for/f loop.

FOR %%C in (ServiceComponent DatamodelComponent SomeXYZComponent ) do (
    call Formalbuild.bat %%C
)

If the list of components is long you could also split them into multiple lines

FOR %%C in (ServiceComponent 
DatamodelComponent
component3
...
component_n
SomeXYZComponent ) do (
    call Formalbuild.bat %%C
)
Sign up to request clarification or add additional context in comments.

Comments

2

Wouldn't a simple counting loop suffice?

for /l %%x in (1,1,N) do call Formalbuild.bat Component%%x

Replace N by the proper number there.

If you want to run this on the command line, then use

for /l %x in (1,1,N) do Formalbuild.bat Component%x

And since there is a PowerShell tag in your question (although you never mention it):

1..N | %{Formalbuild.bat Component$_}

Replace N by the actual value, as usual.

1 Comment

I have updated my question as it was giving assumption that i can loop through by changing last digit.
1
for %%a in (
    Component1
    Component2
    Component3
    ...
    ...
    ComponentN) do call :FormalBuild %%a

:FormalBuild
set THING_TO_BUILD=%1
REM call your build stuff here with %THING_TO_BUILD% identifying what you are building

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.