How do I get the server URL in a script?
I can get the project @job.project@ and id @job.id@, but I would like to get the URL.
we have different instances for dev vs prod, and I want to include a link to the job in the output that is logged in a different system without needing to update the script when it rolls out.
You can suggest that here.
Alternatively, you can extract the value from the rundeck-config.properties
file and store it on a data value (to use in any step/job later), I leave a job definition example:
Command Step:
<joblist>
<job>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>e8bb217c-ec91-418a-aec5-16df83dbcf82</id>
<loglevel>INFO</loglevel>
<name>RundeckServerName</name>
<nodeFilterEditable>false</nodeFilterEditable>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<fileExtension>.sh</fileExtension>
<plugins>
<LogFilter type='key-value-data'>
<config>
<invalidKeyPattern>\s|\$|\{|\}|\\</invalidKeyPattern>
<logData>true</logData>
<regex>^(grails.serverURL)=*(.+)$</regex>
</config>
</LogFilter>
</plugins>
<script><![CDATA[cat /etc/rundeck/rundeck-config.properties | grep 'grails.serverURL']]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
<command>
<exec>echo "the rundeck server url is: ${data.grails.serverURL}"</exec>
</command>
</sequence>
<uuid>e8bb217c-ec91-418a-aec5-16df83dbcf82</uuid>
</job>
</joblist>
Script step:
<joblist>
<job>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>e8bb217c-ec91-418a-aec5-16df83dbcf82</id>
<loglevel>INFO</loglevel>
<name>RundeckServerName</name>
<nodeFilterEditable>false</nodeFilterEditable>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<fileExtension>.sh</fileExtension>
<plugins>
<LogFilter type='key-value-data'>
<config>
<invalidKeyPattern>\s|\$|\{|\}|\\</invalidKeyPattern>
<logData>true</logData>
<regex>^(grails.serverURL)=*(.+)$</regex>
</config>
</LogFilter>
</plugins>
<script><![CDATA[cat /etc/rundeck/rundeck-config.properties | grep 'grails.serverURL']]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
<command>
<fileExtension>.sh</fileExtension>
<script><![CDATA[echo "Rundeck URL is: @data.grails.serverURL@"]]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
</sequence>
<uuid>e8bb217c-ec91-418a-aec5-16df83dbcf82</uuid>
</job>
</joblist>
Here the result.
To use the data variable on another job (dispatched on external nodes) just pass the data value as an argument using the job reference step.
Child job (dispatching commands/scripts to another node):
<joblist>
<job>
<context>
<options preserveOrder='true'>
<option name='rdeck_srv' />
</options>
</context>
<defaultTab>nodes</defaultTab>
<description></description>
<dispatch>
<excludePrecedence>true</excludePrecedence>
<keepgoing>false</keepgoing>
<rankOrder>ascending</rankOrder>
<successOnEmptyNodeFilter>false</successOnEmptyNodeFilter>
<threadcount>1</threadcount>
</dispatch>
<executionEnabled>true</executionEnabled>
<id>3fa71d29-e3bc-453c-a8a7-cb9e95d0a8dd</id>
<loglevel>INFO</loglevel>
<name>ChildJob</name>
<nodeFilterEditable>false</nodeFilterEditable>
<nodefilters>
<filter>name: node01</filter>
</nodefilters>
<nodesSelectedByDefault>true</nodesSelectedByDefault>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<exec>echo "the rundeck server is: ${option.rdeck_srv}</exec>
</command>
</sequence>
<uuid>3fa71d29-e3bc-453c-a8a7-cb9e95d0a8dd</uuid>
</job>
</joblist>
Parent job (takes the server name and pass it to Child job):
<joblist>
<job>
<defaultTab>nodes</defaultTab>
<description></description>
<executionEnabled>true</executionEnabled>
<id>e8bb217c-ec91-418a-aec5-16df83dbcf82</id>
<loglevel>INFO</loglevel>
<name>RundeckServerName</name>
<nodeFilterEditable>false</nodeFilterEditable>
<plugins />
<scheduleEnabled>true</scheduleEnabled>
<sequence keepgoing='false' strategy='node-first'>
<command>
<fileExtension>.sh</fileExtension>
<plugins>
<LogFilter type='key-value-data'>
<config>
<invalidKeyPattern>\s|\$|\{|\}|\\</invalidKeyPattern>
<logData>true</logData>
<regex>^(grails.serverURL)=*(.+)$</regex>
</config>
</LogFilter>
</plugins>
<script><![CDATA[cat /etc/rundeck/rundeck-config.properties | grep 'grails.serverURL']]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
<command>
<fileExtension>.sh</fileExtension>
<script><![CDATA[echo "Rundeck URL is: @data.grails.serverURL@"]]></script>
<scriptargs />
<scriptinterpreter>/bin/bash</scriptinterpreter>
</command>
<command>
<jobref name='ChildJob' nodeStep='true'>
<arg line='-rdeck_srv ${data.grails.serverURL}' />
<uuid>3fa71d29-e3bc-453c-a8a7-cb9e95d0a8dd</uuid>
</jobref>
</command>
</sequence>
<uuid>e8bb217c-ec91-418a-aec5-16df83dbcf82</uuid>
</job>
</joblist>
Here the result.