How to execute remote bat file using build step in TeamCity? - windows

I have TeamCity installed on centos. I have only one Linux BuildAgent for now. My build configuration execute a maven script and using ant upload WAR artifact to Windows Server on FTP. After this step i have to execute BAT file on remote Windows Server. I read that i can do this using psexec/RemCom, but i can't understand how i can do this in TeamCity? Build Step or different Build Configuration should contain steps to execute psexec/RemCom or i can insert Build Step into existed Build Configuration?

Single build configuration could potentially consists of multiple build steps. Think of them as a actions you would like to do. So I suppose that right now you have a maven step in your build configuration. I would suggest you to add Command Line step, where you can do what ever you want -- it's like bash/batch script. You can put script contents directly to the build step, or you can write script and execute it.
But as you mentioned that you have CentOS, it could be you have to do extra configuration on the build agent for PsExec to be available.

Related

Where does Jenkins store the project source

I have a Jenkins job that uses a script to build my project. On the following line, the script fails mvn -e -X -Dgit='$git' release:prepare.
Because I want to search for the cause of this, I want to go to the Jenkins server and run mvn -e -X -Dgit='$git' release:prepare from the command line, to see if it works.
Does Jenkins store the projects' source code somewhere, such that I can go to that folder and call Maven?
If yes, then where?
Yes, It Stores the project files for the job by default at
/var/lib/jenkins/workspace/{your-job-name}
This is where jenkins suppose the project files to be present or it pulls it from a source before start working/building from it.
Quote from Andrew M.:
"Hudson/Jenkins doesn't quite work that way. It stores configurations and job information in /var/lib/jenkins by default (if you're using the .deb package). If you want to setup persistence for a specific application, that's something you'll want to handle yourself - Hudson is a continuous integration server, not a test framework.
Check out the Wiki article on Continuous Integration for an overview of what to expect."
From this Question on serverfault.
This worked for me:
/var/jenkins/workspace/JobNameExample
but, if your build machine (node) is a different than the one where Jenkins is running (manager), You need specify it:
/var/jenkins/workspace/JobNameExample/label/NodeName
Where you can define label too:
jenkins stores its workspace files currently in /var/jenkins_home/workspace/project_name
I am running from docker though!

In teamcity, can an artifact be executed in a build step?

For example, project A generates two artifacts processor.exe and t.txt. Then in project B, can I add a build step to execute processor.exe t.txt?
I know there are two Runner types(.NET Process Runner and Command Line) that can execute programs. But how to get the paths of these artifacts?
Yes, I think it should be possible to run with Command Line runner *.exe file generated by other build.
You just have to make sure that build agent which runs Project A outputs these artifacts to place where build agent which runs Project B has access (in case if you have single agent it's not a concern obviously). And probably placing these artifacts into agent's working directory is not the best place because it can be cleared by doing clean checkout from VCS. Just choose some generic directory on the server and specify it for artifact output in Project A and then for Command Line runner in Project B.

Copying files between two windows servers through jenkins

I am working on a project where i want to copy the compiled file (which compiled through jenkins) from one windows server to another through jenkins. Jenkins is installed on a windows server and after building the code, those compiled file should be copied to another windows server through jenkins. Is there any way to achive it?
Jenkins might be able to do it, via the script steps running the scp command; however, if this is part of a build, I would suggest attaching the file(s) to a project, and distributing them through the maven repository.

how to execute shell to install a file from artifacts dir in jenkins

I have a build step that builds my projects and packs it into a myfile.jar and put it in my artifacts dir.
i have also told jenkins to archive the myfile.jar.
now i want to add another build step to execute shell command java -jar myfile.jar and install it for further testings
how can i tell jenkins to point to myfile.jar when executing the shell command ? i don't know the artifacts dir name since it's dynamically created with build number etc...
thanks.
The artifacts directory is on the master, not the slave.
If both are on the same machine for you, the artifacts reside at:
$JENKINS_HOME/jobs/$JOB_NAME/$BUILD_ID/archive
However, like Anders Lindahl said, archiving an artifact does not delete it from the workspace; why not use it directly from there. Generally, you do not want to disturb the archives directories...

hudson for newbies: how do i run software after successful build

i'm new to world of continuous integration and software developement.
I wanted to try hudson so i installed it on my ubuntu machine and created a new job. i pointed it to an open source project's svn (keepassx) just to try.
Hudson downloaded everything from the repository and marked blue for successful build.
aren't i suppose to be able to execute the software now somehow ? i thought once it is built i can run it, but i can't find any executable in the project's home page under hudson user home dir.
thanks.
A Hudson/Jenkins build breaks down into three steps:
update source code in workspace
run build
publish build artifacts
It sounds like you've got step 1 covered.
If the project you linked to has instructions for building (ant, maven, etc.), you can enter these as build steps into the "Build" section of the project configuration.
You can then take the resulting files ("artifacts"--jar, exe, so, bin, whatever) and publish these using the "Post-build Actions", or if necessary you can grab them directly from the workspace filesystem.
Assuming the build artifact was an executable, you could then run it after downloading it from Hudson, or make a build step or post-build action which moved it into the appropriate location and ran it.
It helps to run the build locally before trying to get Hudson to handle it--then you know what the build steps are, and what the final build artifacts are.
How would jenkins/hudson know how to 'execute' some arbitrary package that you told it to download and build? It's up to you to write a program or script to run what you want to run, and then make a downstream job (for example) to do so.

Resources