Ant move, copy tasks failing on mapped drives in jenkins - ant

I have an ant file which has move and copy tasks. The source and destination locations are on the mapped network drive R:\. When I run them on the command prompt the build is successful but when I configure it as a job in Jenkins, the tasks are failing with the below console output.
BUILD FAILED
C:\Users\admin\.jenkins\jobs\CopyTask\workspace\build.xml:24: R:\dest does not exist.
Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE
Both the standalone build and Jenkins build are under the same user credentials.
I have looked in the the questions copy in ANT throws java.io.FileNotFoundException and
Ant Copy Task: Failed to copy due to java.io.FileNotFoundException but it didn't help me solve the issue.
EDIT
Jenkins service was running under local system account and in Jenkins app, I was using "Jenkins's own user database" for Security Realm. I had created a user called "admin" with all the permissions granted. After looking in to this link, I installed Active Directory Plugin and used an administrator account credentials to start the Jenkins service. But still I am getting the below error message
BUILD FAILED
C:\Users\admin\.jenkins\workspace\CopyTask\build.xml:11:
Failed to copy C:\Users\admin\FldrToCopy\data.7z to
R:\data.7z due to failed to create the parent directory for R:\data.7z
Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE

Obviously, the system account you're using doesn't have this mapped drive. Before copying, try to map the drive through the Windows net use command. In Jenkins, you can run this in your build steps as a shell command before you execute your Ant script.
I don't have a Windows machine in front of me, but it should look something like this:
net use R: /delete
net use R: /persistent:yes \\windows\share\path
You want to do the net use R: /delete first to remove any already existing mapping.
If this doesn't work, try this. This will help you create a mapped drive to your system account that always exist.

What user account is Jenkins running as? If it's running as the SYSTEM account, then it probably can't see the mapped drive. Take a look at Map a network drive to be used by a service for some ideas.
Or perhaps you could use the UNC path instead of the mapped drive?

Related

SoapUI test execution returns error "The directory name is invalid"

I have an established CI pipeline comprising (prior to deployment):
TFS build
JFrog Artifactory for build artifact management
SoapUI and SpecFlow (BDD & itaretive, parameterised) for web service functional test automation
I have no access to our build agent servers and no permission to install anything thereon. Instead, I've added the SoapUI binaries as links to my functional test project; the binaries are pulled from source control in the Get Sources step of every build.
This works okay but it greatly increases the footprint of my test project (and any other test project for which SoapUI would be required), and by extension, the execution time of the build: functional testing will only execute on a small fraction of the builds executed (only if application codebase has changed or sufficient time interval since last full build and test has elapsed).
For these reasons, I opted to remove the SoapUI binaries folder from my test project and instead deploy a SoapUI binaries zip archive to an Artifactory repository. With the addition of a PowerShell script step in my build definition, I can pull the SoapUI binaries as needed and extract to the desired location on the build server. Foolishly, I thought this might be straightforward...
I did manage to push the zipped SoapUI binaries folder to the Artifactory repo, and, in my Development build definition, I did manage to correctly script my PowerShell step to pull the zip archive and extract its content successfully to he same folder in the build binaries directory on the build agent server as it had been located originally.
However, when I execute my build, in the step where the SoapUI tests are executed, on the first test iteration, I see the following error returned to build console:
System.ComponentModel.Win32Exception: The directory name is invalid
I added a PowerShell scripted filtered folder content step before the test execution step in both my Development (new) and my Production (original) builds for comparison. Both show the required 'testrunner.bat' to be present, in the same folder on the build agent server.
The test project itself has been unchanged (except for the removal of the SoapUI binaries folder).
To summarise:
I'm trying to execute SoapUI tests in two builds; in each build, the same test project is used and the SoapUI binaries are in the same location when the test execution kicks off.
One build executes successfully without issue.
One build fails at test execution step, returning error "System.ComponentModel.Win32Exception: The directory name is invalid".
I'm very puzzled by this; insights and SoapUI wisdom most welcome.
Thanks for looking.
Turned out, there was a discrepancy in the directory paths on the testrunner.bat between the builds; a '_' where a '-' should have been

Gradle copy file task fails to copy to mapped network drive via Jenkins

I am using Jenkins and running Gradle tasks to build a jar, executable and a setup.exe file. One of my gradle tasks is to copy the built setup.exe file to mapped network drive on the agent in runs on.
I am trying to copy the setup file to a folder on the mapped drive called 2.x.
I get the error:
"Cannot convert URL 'z:/Developers/Projects/builds/v2.x/' to a file."
task copySetup(type: Copy) {
from file("${projectDir}/Setup.exe")
into file ("z:/Developers/Projects/builds/v2.x")
}
If I run the task myself in the workspace then it works. Only fails when Jenkins runs it. I use a Gradle wrapper so it shouldn't be a Gradle version issue I think.
So I got my answer from this post by ForcePush: Map a network drive to be used by a service
Even though Jenkins runs as the user account I used to map the network drive, the service does not see any mapped network drives. The answer by ForcePush solves this problem.

TFS Release CopyFiles task gives code EPERM

I'm running latest version of TFS 2015 release manager. I have a simple release that includes a "CopyFiles" task. I need to have the "Clean Target Folder" option of the task enabled.
I have three target environments configured. Both are newly created identical Windows servers. The CopyFiles task works fine against the first two servers but for the next environment in the pipeline, when copying to the second server I get the following error:
2016-11-11T21:41:07.4324714Z found 2 files
2016-11-11T21:41:07.4324714Z ##[debug]file:D:/Build/_work/df9f2c4cf/(master) Orchard BTDF/drop/20161111.5.zip will be copied.
2016-11-11T21:41:07.4324714Z ##[debug]file:D:/Build/_work/df9f2c4cf/(master) Orchard BTDF/drop/Unzip.ps1 will be copied.
2016-11-11T21:41:07.4324714Z Cleaning target folder: \\Steatbt02\BizTalkDeployments2\Orchard
2016-11-11T21:41:07.4324714Z ##[debug]rm -rf \\Steatbt02\BizTalkDeployments2\Orchard
2016-11-11T21:41:07.4480915Z rm: could not remove directory (code EPERM): \\Steatbt02\BizTalkDeployments2\Orchard
2016-11-11T21:41:07.4480915Z ##[debug]task result: Failed
There's no sign of errors in the event log.
I created the share "\Steatbt02\BizTalkDeployments2" and granted "full-access" permissions to the account running the build agent. I even tried logging onto the build server and run as for the command prompt using the credentials of the build agent. From this command window I was able to remove the target folder
"\Steatbt02\BizTalkDeployments2\Orchard" - so I can't think why the build agent would have trouble doing the same!
Any ideas what could be wrong, or what extra steps I could take to track down the root cause of the problem?
The problem was the agent queue selected for the problem environment.

Jenkins deleting batch file before it's completed

I'm running Jenkins on a Server 2012 VM, and I'm noticing that some of my projects are being marked as incomplete when they are successful. I am getting the error 'The batch file cannot be found.' The problem, from what I can tell, is that the batch file Jenkins is creating to run my project is being deleted before it's completed. I'm migrating from a windows 7 box where this issue doesn't happen.
I've been able to watch as the batch file is created in C:\Users\164016\AppData\Local\Temp\ and then it's deleted before the batch file completes. I'm even able to open the batch file before it's deleted.
I've tried placing the Call command at the beginning of the command, but that doesn't resolve the issue.
The LaunchPad.exe command is a custom made script designed to return exit codes from Excel vba macros.
Please let me know if you have any suggestions.
Here is the log:
Building remotely on (164016) Remote Computer in workspace C:\TEMP\Jenkins Slave\workspace\Weekly Claim Edit WQ Age
[Weekly Claim Edit WQ Age] $ cmd /c call C:\Users\164016\AppData\Local\Temp\hudson3188220465265190989.bat
C:\TEMP\Jenkins Slave\workspace\Weekly Claim Edit WQ Age>"O:\Analytics Team\Tasks\Automation Components\Ryan\C#\Launch Pad\LaunchPad\LaunchPad\bin\Debug\LaunchPad.exe" "C:\Program Files (x86)\Quest Software\Toad for Data Analysts 2.7\Toad.exe" -batch=true "O:\Analytics Team\Tasks\Automation Components\Cindy\TAS\Claim_Edit_WQ_Age.tas" "O:\Analytics Team\Tasks\Claim Edit WQ Age\Claim_Edit_WQ_Age.xlsm"
LaunchPad Start Time: 10.7.2014 9:49:10 AM
Time before Stopping Programs: 60 min
Program: "C:\Program Files (x86)\Quest Software\Toad for Data Analysts 2.7\Toad.exe"
Arguments: "-batch=true" "O:\Analytics Team\Tasks\Automation Components\Cindy\TAS\Claim_Edit_WQ_Age.tas"
vba File: "O:\Analytics Team\Tasks\Claim Edit WQ Age\Claim_Edit_WQ_Age.xlsm"
vba Exit File: O:\Analytics Team\Tasks\Claim Edit WQ Age\Claim_Edit_WQ_Age.txt
Report Completed: 10/7/2014 9:50:28 AM 164016 O:\Reports\EPIC\Epic Claim Edit WQ\20141007 Claim Edit WQ Age.xlsx
Exiting LaunchPad: No Errors Detected: 0
The batch file cannot be found.
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
I had a very similar problem. I was running a job in Jenkins that was calling a specialized internal program and causing the "batch file not found" error. It turns out there was a del %TEMP%\*.* /q command in one of the batch files being run. This was deleting all of the Jenkins temporary batch files in the middle of the job and causing the error.
The simple solution is to simply relocate the Jenkins temp folder. This can be done by adding a command line option to your Jenkins startup script. My startup script looks like: java -XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -Djava.io.tmpdir=C:\Users\!!My_user_name!!\Desktop\Jenkins_Temp -jar jenkins.war
The important part I added was the -Djava.io.tmpdir=C:\Users\!!My_user_name!!\Desktop\Jenkins_Temp option (Removed my user name for privacy reasons.) This fixed the problem. Don't forget to replace my path with with a valid path name for your system.
The command line option should be added to both the master and slave startup scripts for proper operation.
You've got something else at play here...
When you configure Execute Windows batch command build step, it creates a temporary batch file that Jenkins then executes.
The execution of the temporary batch file starts at:
[Weekly Claim Edit WQ Age] $ cmd /c call C:\Users\164016\AppData\Local\Temp\hudson3188220465265190989.bat
and it finishes at:
Build step 'Execute Windows batch command' marked build as failure
The temporary batch file hudson3188220465265190989.bat would be deleted after that last line.
Your error The batch file cannot be found. happens before that line. So, it's not the Jenkins temporary batch file that cannot be found, but something else.
Unless you provide the content of your Execute Windows batch command, it's difficult to guess what else could be the problem.

Running a Windows batch file in Jenkins

I trying to run my Tests cases for a project in Jenkins through DOS Command line on Windows server . I am using Jenkins ver. 1.559.
I am trying to run a Windows batch file through a Jenkins job that has the java command.
Under the "Build" section >> "Execute Windows Batch command" >> Command: call E:\Jenkins\App\UnitTests\App_UnitTests.bat
Save and Build the job.
I am getting an error and here is my Console Output
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>java.exe -cp "E:\Jenkins\App\PPS\App\bin\;E:\Jenkins\App\PPS\App\lib\junit-4.10.jar;E:\Jenkins\App\PPS\App\lib\*.jar;" org.junit.runner.JUnitCore com.omnitracs.fra.junit.EventTests
'java.exe' is not recognized as an internal or external command, operable program or batch file.
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>PAUSE
Press any key to continue . . .
C:\Program Files (x86)\Jenkins\jobs\App Test Cases\workspace>EXIT
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
The java command runs fine outside Jenkins.
I have set the JAVA_HOME for the local user and also the PATH variable to point to where java.exe is.
What am I doing wrong? Please help.
For a windows environment, there is some extra configuration needed for more advanced builds. Ultimately you have two options
From Jenkins, The Definitive Guide:
This basic installation will work fine in a simple context, but you
will often need to fine-tune your service. For example, by default,
the Jenkins service will be running under the local System account.
However, if you are using Maven, Jenkins will need an .m2 directory
and a settings.xml file in the home directory. Similarly, if you
are using Groovy, you might need a .groovy/lib directory. And so on.
To allow this, and to make testing your Jenkins install easier, make
sure you run this service under a real user account with the correct
development environment set up. Alternatively, run the application as the
system user, but use the System Information page in Jenkins to check
the /Users/johnsmart/Projects/Books/jenkins-thedefinitive- guide
directory, and place any files that must be placed in the user home
directory here....
To configure your Jenkins server to run under a service account (The suggested option), Install Jenkins as a service, and under the services properties set the log on user info.

Resources