I would like to set a variable that I need to use during build only. The variable should be set differently based on the user that runs the build procedure. For example, if user that runs the build is X set variable to some predefined fixed value, else, set it to ${system_username}.

asked 16 Apr '12, 06:10

NicoleH's gravatar image

NicoleH
66202023
accept rate: 50%


We will investigate making the ${system_username} variable available at build time. As a workaround you can set it manually by doing:

<setInstallerVariable>
    <name>system_username</name>
    <value>${env(USERNAME)}</value>
    <ruleList>
        <compareTextLength>
            <length>0</length>
            <logic>greater</logic>
            <text>${env(USERNAME)}</text>
        </compareTextLength>
    </ruleList>
</setInstallerVariable>
<setInstallerVariable>
    <name>system_username</name>
    <value>${env(LOGNAME)}</value>
    <ruleList>
        <compareTextLength>
            <length>0</length>
            <logic>greater</logic>
            <text>${env(LOGNAME)}</text>
        </compareTextLength>
    </ruleList>
</setInstallerVariable>
<setInstallerVariable>
    <name>system_username</name>
    <value>${env(USER)}</value>
    <ruleList>
        <compareTextLength>
            <length>0</length>
            <logic>greater</logic>
            <text>${env(USER)}</text>
        </compareTextLength>
    </ruleList>
</setInstallerVariable>

This will use USERNAME, LOGNAME and USER environment variables to get the user name, in that order.

link

answered 16 Apr '12, 09:36

wojciechka's gravatar image

wojciechka ♦♦
7.8k61122
accept rate: 26%

The <if> action can be used to set a value based on ${system_username} variable:

<if>
    <actionList>
        <!-- if ${system_username} equals X, set to predefined value -->
        <setInstallerVariable>
            <name>variable_name</name>
            <value>value</value>
        </setInstallerVariable>
    </actionList>
    <elseActionList>
        <!-- if ${system_username} does not equal X, set to other value -->
        <setInstallerVariable>
            <name>variable_name</name>
            <value>${system_username}</value>
        </setInstallerVariable>
    </elseActionList>
    <conditionRuleList>
        <compareValues>
            <logic>equals</logic>
            <value1>${system_username}</value1>
            <value2>X</value2>
        </compareValues>
    </conditionRuleList>
</if>

The action is described in more details in the If / Else section of InstallBuilder User Guide.

link

answered 16 Apr '12, 07:33

wojciechka's gravatar image

wojciechka ♦♦
7.8k61122
accept rate: 26%

I'm trying to use this functionality in pre-build actions, but system_username is not accessible in pre-build action.

(16 Apr '12, 07:57) NicoleH
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×155

Asked: 16 Apr '12, 06:10

Seen: 1,401 times

Last updated: 16 Apr '12, 09:36