Access remote system from ant script failes

Hello *,

we have got an ant script which should access a remote system after building a java project to distribute it.
The target in our build.xml looks like this:

    <!-- ==================== Run deployment Target ============================= -->
    <target name="deployment" description="deploy project to test server">

        <!-- kill running test server on remote system -->
        <exec executable="cmd.exe">
            <arg line="/c taskkill /S ip.of.remote.system /U user_of_remote_system /P password_of_remote_system /IM cmd.exe /T"/>
        </exec>

        <!-- build, unzip and other stuff -->
        [ ... ]

        <!-- delete old folders on test server-->
        <delete dir="${testserver.mappeddir}/${app.name}" />
        [ ... ]

        <!-- move folders to test server (name without version number) -->
        <move file="${tempdir}/${dist.name}" tofile="${testserver.mappeddir}/${app.name}"/>
        [ ... ]
        <delete dir="${tempdir}" />

        <!-- start test server -->
        <exec executable="psexec.exe">
            <arg line="\\ip.of.remote.system -d -i -u user_of_remote_system -p password_of_remote_system -w D:/Test-Server cmd /c &quot;1 Test-Server starten.lnk&quot;"/>
        </exec>

    </target>

${testserver.mappeddir} points to a folder on the remote system (is mapped as a network drive Z: on the build system). The network drive connection is established by an admin user on each startup/ logon. Running the script from command line within this user account works just fine but running it from TeamCity the build fails with the following error message:

[11:50:48]: [deployment] exec (38s)
[11:51:26]: [exec] FEHLER: Anmeldung fehlgeschlagen: unbekannter Benutzername oder falsches Kennwort. [error: logon failed. unknown user or password - this is an error caused by the first exec command]

[11:51:26]: [exec] Result: 1
[11:52:02]: [deploymentvistahro] move
[11:52:02]: [move] Failed to copy C:\TeamCity\buildAgent\work\TestServer_DeploymentBuild\temp\TestServer-1.0.15\bin\lib\commons-cli-1.0.jar to Z:\TestServer\bin\lib\commons-cli-1.0.jar due to Z:\TestServer\bin\lib\commons-cli-1.0.jar (Das System kann den angegebenen Pfad nicht finden) [system can not locate given path]


It seems that TeamCitys Build service runs on the local system account and has no rights to access the remote system (or the mapped drive due to its establishment by a specific user). So we changed the service "TeamCity Build Agent Service" to run with the admin user which leads to another error message:

[11:57:06]: [deployment] exec
[11:57:06]: [exec] Der Befehl "taskkill" ist entweder falsch geschrieben oder
[11:57:06]: [exec] konnte nicht gefunden werden. [the commant "taskkill" either is written wrong or could not be located]

[11:57:06]: [exec] Result: 1
[11:57:45]: [deploymentvistahro] move
[11:57:45]: [move] Failed to copy C:\TeamCity\buildAgent\work\TestServer_DeploymentBuild\temp\TestServer-1.0.15\bin\lib\commons-cli-1.0.jar to Z:\TestServer\bin\lib\commons-cli-1.0.jar due to Z:\TestServer\bin\lib\commons-cli-1.0.jar (Das System kann den angegebenen Pfad nicht finden) [system can not locate given path]


Why it is possible to access the remote system while running the script from the command line but not from tc ant build runner? I can imagine that there could be problems using the network drive but I was sure the first exec command in the script should work in every scenario. Any suggestions?


Thanks in advance for help.


Regards
Enrico
2 comments
Comment actions Permalink

Windows service cannot access mapped network drives. This is limitation of Windows OS. There are two workarounds:
- run agent via agent.bat
- use UNC paths to access network directories

0
Comment actions Permalink

Problem solved.

I realised that I have to pass a domain to the user name (which simply is the ip of the remote system). Additionally I connect to network drive directly within the script. My final build.xml target lokks like this:

    <!-- ==================== Run deployment Target ============================= -->
    <target name="deployment" description="deploy project to test server">

        <property name="ip" value="ip" />
        <property name="user" value="${ip}\TestServer" />
        <property name="pw" value="pw" />
        <property name="mappeddir" value="Z:" />
    
        <!-- map network drive -->
        <exec executable="cmd.exe">
            <arg line="/c if not exist ${mappeddir} net use ${mappeddir} \\${ip}\Test-Server ${pw} /USER:${user}"/>
        </exec>
    
        <!-- kill running test server on remote system -->
        <exec executable="cmd.exe">
            <arg line="/c taskkill /S ${ip} /U ${user} /P ${pw} /IM cmd.exe /T"/>
        </exec>
     
        <!-- build, unzip and other stuff -->
        [ ... ]

        <!-- delete old folders on test server -->
        <delete dir="${mappeddir}/${app.name}" />
        [ ... ]

        <!-- move folders to test server (name without version number) -->
        <move file="${tempdir}/${dist.name}" tofile="${mappeddir}/${app.name}"/>
        [ ... ]
        <delete dir="${tempdir}" />

        <!-- start test server -->
        <exec executable="psexec.exe">
            <arg line="\\${ip} -d -i -u ${user} -p ${pw} -w D:/Test-Server/${app.name} cmd /c server.bat"/>
        </exec>
    
        <!-- disconnect network drive -->
        <exec executable="cmd.exe">
            <arg line="/c if exist ${mappeddir} net use ${mappeddir} /delete"/>
        </exec>

    </target>

Astonishing - once you make it right it works

@Pavel: Nevertheless thanks for your suggestions.

Regards
Enrico

0

Please sign in to leave a comment.