CVS checkout without all of extra folders - jenkins

I want to checkout a specific folder from deep within a CVS module into my Hudson / Jenkins workspace. Stripping off the other options (such as pruning, branch, etc) the CVS command is ...
cvs checkout -d workspace module\a\b\c\d\e\f
This causes my folder to contain a child folder 'a' and that contains 'b' and that contains ... well you get the idea. All of them are empty until you get down to folder 'f'.
What I'd really like is for myfolder to contain the contents of f. Does CVS support this functionality (without defining f as a module)?
And for bonus karma ... Can I get Jenkins to use this option with a .cvsrc or some other mechanism?

I don't get the behaviour you describe. When I move to an empty directory and do
cvs checkout -d fox modules/a/quick/brown/fox
I just get a new directory called fox containing the contents of the directory I requested. (Note the forward slashes.)
However, if I do
cvs checkout modules/a/quick/brown/fox
then I get what you describe.
I'm using the latest FSF build of CVS on windows, http://ftp.gnu.org/non-gnu/cvs/binary/feature/x86-woe/cvs-1-12-13a.zip .

There is a file called "modules", under your CVSROOT folder.
You can edit it, and a line like the following:
###shortcut name actual path########
f /a/b/c/d/e/f
Check this file back in. Once it sets in, you can just use
cvs checkout -d workspace f
Also, in Hudson, you can (in the Modules(s) ) box, just put f, and it should directly download only f, instead of the entire structure.
Once that is down, you could rename it using a shell/command.

More in General:
Go up 1 level above where you checked out
cvs co -r "TAG"

Related

Stripping GIT_BRANCH to get the verison

I have branch with this format: release/1.0.0
When I use ${GIT_BRANCH}, I get the following: origin/release/1.0.0
I have tried using EnvInj to set a variable like this:
If I leave ${GIT_BRANCH} the way it is it works fine, but if i use ${GIT_BRANCH, fullName=false}. It is always a empty string.
I have also tried using: How to receive local Git branch name with Jenkins Git plugin?
What is correct format to get just 1.0.0.0-rc134
You can always write a small bash script to get this done.
Use a execute shell build step
echo "RELEASECANDIDATE=${GIT_BRANCH##*/}-rc${BUILD_NUMBER}" > ${WORKSPACE}/inject.txt
Use a Inject shell and in the properties file section give the file name
${WORKSPACE}/inject.txt
Finally in the update build name , use macro below variable
${RELEASECANDIDATE}
This should get you correct value as expected
Use below command at execute bash to get any part of the branch string you want. I am getting the mid part here. Keep in mind it starts counting from left and from 1.
SUBSTR=$(echo $GIT_BRANCH | cut -d'/' -f 2)
I continued the search and found a better solution for this problem at the link below. Basically rather than using $GIT_BRANCH, you can add one additional behaviour after git pull and "check out to specific local branch" and then use $GIT_LOCAL_BRANCH that will return what you expect and is compatible with all plugins (at least with FTP plugin that I used). Please see it in more details at the link below:
How to receive local Git branch name with Jenkins Git plugin?
Try to get ${GIT_LOCAL_BRANCH}. It returns only branch name.

ClearCase claims directory is both checked out and not checked out

I am using Jenkins to manipulate files and directories in Base ClearCase. I am executing the batch file
cd /D M:\view\path\to\stuff\Jenkins
echo Test to see if Jenkins can add things to ClearCase> foo.txt
cleartool checkout .
cleartool mkelem foo.txt
and I get the output
M:\jenkins_dynamic\CSTS\01_Build\Automated_Build\Jenkins>cleartool checkout .
cleartool: Error: Element "." is already checked out to view "jenkins_dynamic".
M:\jenkins_dynamic\CSTS\01_Build\Automated_Build\Jenkins>cleartool mkelem foo.txt
cleartool: Error: Can't modify directory "." because it is not checked out.
What am I missing here?
Double-check your dynamic view config spec, as in this technote, with cleartool catcs:
cleartool catcs -tag jenkins_dynamic
The cause of this error relates to the current view's config_spec; it may have a -mkbranch rule or use an existing branch name for a branch type that is not mastered at the local site.
If the parent directory can't be checked out on the non-mastered branch, then new elements can't be created in that directory.
Example: this config spec (without the loading rules, since you are in a dynamic view).
Make sure all the parents folders are accessible and visible.
So that kind of error could be in the context of a multi-site ClearCase.

How to name local workspace using command line interfaces while checking out files from CVS repository by means of a tag

Right now i am using below mentioned cvs command line argument for checking out files from CVS repository.
# Module1_1_20_2017 is the tag name.
#Test/user_Test/work is the module name.
cvs checkout -r Module1_1_20_2017 Test/user_Test/workload
I want contents of this Test/user_Test/workload module to be checked out into a local workspace folder named as work which is located at C:\Jenkins\jobs\workspace\work.
But every time when i use the above command it creates empty directories after this C:\Jenkins\jobs\workspace\work local workspace as C:\Jenkins\jobs\workspace\work\Test\user_Test\workload.
I want to get rid of these entire folders Test\user_Test\workload and after checking out files from Test/user_Test/work this module the local workspace should look like C:\Jenkins\jobs\workspace\work (not C:\Jenkins\jobs\workspace\work\Test\user_Test\workload) and this local workspace C:\Jenkins\jobs\workspace\work should contain all the files of this Test/user_Test/workload module.
What cvs command line will satisfy this requirement?In short I want to create a local name as in jenkins job configuration shown in the picture attached below.
Use the form cvs checkout -d <path> <module>.
In your case that is cvs checkout -d work Test/user_Test/workload
(Did cvs checkout --help not give you this answer?)

Jenkins "Console Output" log location in filesystem

I want to access and grep Jenkins Console Output as a post build step in the same job that creates this output. Redirecting logs with >> log.txt is not a solution since this is not supported by my build steps.
Build:
echo "This is log"
Post build step:
grep "is" path/to/console_output
Where is the specific log file created in filesystem?
#Bruno Lavit has a great answer, but if you want you can just access the log and download it as txt file to your workspace from the job's URL:
${BUILD_URL}/consoleText
Then it's only a matter of downloading this page to your ${Workspace}
You can use "Invoke ANT" and use the GET target
On Linux you can use wget to download it to your workspace
etc.
Good luck!
Edit:
The actual log file on the file system is not on the slave, but kept in the Master machine. You can find it under: $JENKINS_HOME/jobs/$JOB_NAME/builds/lastSuccessfulBuild/log
If you're looking for another build just replace lastSuccessfulBuild with the build you're looking for.
Jenkins stores the console log on master. If you want programmatic access to the log, and you are running on master, you can access the log that Jenkins already has, without copying it to the artifacts or having to GET the http job URL.
From http://javadoc.jenkins.io/archive/jenkins-1.651/hudson/model/Run.html#getLogFile(), this returns the File object for the console output (in the jenkins file system, this is the "log" file in the build output directory).
In my case, we use a chained (child) job to do parsing and analysis on a parent job's build.
When using a groovy script run in Jenkins, you get an object named "build" for the run. We use this to get the http://javadoc.jenkins.io/archive/jenkins-1.651/hudson/model/Build.html for the upstream job, then call this job's .getLogFile().
Added bonus; since it's just a File object, we call .getParent() to get the folder where Jenkins stores build collateral (like test xmls, environment variables, and other things that may not be explicitly exposed through the artifacts) which we can also parse.
Double added bonus; we also use matrix jobs. This sometimes makes inferring the file path on the system a pain. .getLogFile().getParent() takes away all the pain.
You can install this Jenkins Console log plugin to write the log in your workspace as a post build step.
You have to build the plugin yourself and install the plugin manually.
Next, you can add a post build step like that:
With an additional post build step (shell script), you will be able to grep your log.
I hope it helped :)
Log location:
${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_NUMBER}/log
Get log as a text and save to workspace:
cat ${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_NUMBER}/log >> log.txt
For very large output logs it could be difficult to open (network delay, scrolling). This is the solution I'm using to check big log files:
https://${URL}/jenkins/job/${jobName}/${buildNumber}/
in the left column you see: View as plain text. Do a right mouse click on it and choose save links as. Now you can save your big log as .txt file. Open it with notepad++ and you can go through your logs easily without network delays during scrolling.
I found the console output of my job in the browser at the following location:
http://[Jenkins URL]/job/[Job Name]/default/[Build Number]/console
This is designed for use when you have a shell script build step. Use only the first two lines to get the file name.
You can get the console log file (using bash magic) for the current build from a shell script this way and check it for some error string, failing the job if found:
logFilename=${JENKINS_HOME}/${JOB_URL:${#JENKINS_URL}}
logFilename=${logFilename//job\//jobs\/}builds/${BUILD_NUMBER}/log
grep "**Failure**" ${logFilename} ; exitCode=$?
[[ $exitCode -ne 1 ]] && exit 1
You have to build the file name by taking the JOB_URL, stripping off the leading host name part, adding in the path to JENKINS_HOME, replacing "/job/" to "/jobs/" to handle all nested folders, adding the current build number and the file name.
The grep returns 0 if the string is found and 2 if there is a file error. So a 1 means it found the error indication string. That makes the build fail.
Easy solution would be:
curl http://jenkinsUrl/job/<Build_Name>/<Build_Number>/consoleText -OutFile <FilePathToLocalDisk>
or for the last successful build...
curl http://jenkinsUrl/job/<Build_Name>/lastSuccessfulBuild/consoleText -OutFile <FilePathToLocalDisk>

Using ant to add directories to CVS

How do I add a new directory into my CVS repository using Ant? From all that I've read, it appears that I have to cd to the parent directory and call the cvs command. How do I do that in Ant? I've seen approaches where an to cd is called in Ant; is that the best approach?
Eg of what I am trying to do:
Let's say I have a module Test_Module with directories "A", "B" and "C". Under each of these directories, there are directories for "Jan", "June", "Sept" and I want to create a "Alpha" directory under Test_Module-> C -> Sept.
So, I create a "Alpha" directory on my local system and run the cvs add command from Root and I get the following errror:
cvs add: in directory .:
cvs [add aborted]: there is no version here; do 'cvs checkout' first
I get the same error when I run this using Ant or from command line.
Now, if I cd to the Test_Module/C/Sept directory and run "cvs add Alpha" it creates the directory and everything is fine. So, how do I do the same in Ant? Are there any ant-contrib tasks that are out there that I could possibly use or even a built-in ant task that I am missing?
Thanks in Advance!!
did you look at the Ant CVS task?
I haven't used CVS for a while but since it's possible to manage a Subversion repository with Ant, I guess there should be no problem to do it for CVS

Resources