Problem
I have a selenium suite that takes over 4 hours to run. I'm trying to cut down that time in simple way.
My approach:
1) I created 3 branches, each branch has a different testng.xml file; by different, I mean that every testng.xml file runs a different set of tests.
2) I created 3 Jenkins jobs, each job should run the testng.xml file from one of the 3 branches.
Problem:
Every time I try to run my build, it seems that the testng.xml file in my master branch gets built.
Things I tried:
1) I tried specifying the name of my branch in the Branches to build's "Branch Specifier", but that didn't work.
2) I also tried adding the entire path of my branch as the "Repository URL" (eg. https://github.com/myProject/tree/branchTwo), but I get a status code 128 back
Goal:
I'm wondering if there's some configuration my Jenkins jobs to run each of the three jobs manually?
You can simply add branch name and Run
ADD repository URL and Branch name on a branch to build the field. If your project is maven project you can run any class using shell command.
Example:
sudo mvn exec:java -D exec.mainClass=owasp.SiteVisit
adding a remotes/origin/branchName did it. Thanks # Joao Vitorino
Related
I'm new to Jenkins and am trying to setup CI for my iOS app. I've created a unit test target in the project and have configured Jenkins to properly build and run my unit tests, but the build fails when trying to actually output the rest results xml file and I'm not sure what I'm doing wrong. I borrowed a lot of ideas presented from these sources:
https://www.raywenderlich.com/22816/beginning-automated-testing-with-xcode-part-22
http://www.sailmaker.co.uk/blog/2013/04/02/advanced-jenkins-for-ios-and-mac/
My actual console log after a build looks like this:
=== BUILD TARGET run_to_it OF PROJECT run_to_it WITH CONFIGURATION Debug ===
Check dependencies
=== BUILD TARGET run_to_itTests OF PROJECT run_to_it WITH CONFIGURATION Debug ===
Check dependencies
** BUILD SUCCEEDED **
Recording test results
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
Finished: FAILURE
My build step execute shell looks like this :
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
security unlock-keychain -p ${KEYCHAIN_PASSWORD} ${KEYCHAIN_PATH}
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k ${KEYCHAIN_PASSWORD} ${KEYCHAIN_PATH}
xcrun xcodebuild clean build CODE_SIGN_IDENTITY="${CODE_SIGNING_IDENTITY}" PROVISIONING_PROFILE=${PROVISIONING_PROFILE} OTHER_CODE_SIGN_FLAGS="--keychain ${KEYCHAIN_PATH}"
xcodebuild -target run_to_itTests -configuration Debug -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO TEST_AFTER_BUILD=YES GCC_TREAT_WARNINGS_AS_ERRORS=NO WANT_IOS_SIM=YES OBJROOT="${WORKSPACE}"/tmp/objs build | /usr/local/bin/ocunit2junit
My post build step for where the test reports are to be placed looks like this:
I've ensured I've installed the necessary plugins as well as installing the ocunit2junit gem in the /usr/local/bin directory as well as having installed the JUnit plugin in Jenkins.
I'm not 100% sure if any xml file is being generated at all as I've looked through every folder in the Jenkins workspace and see no such xml file anywhere. I'm not sure if I need to explicitly specify this file to be created in any of the build steps or if it is handled by default. I've looked far and wide on the internet and I've not been able to conclusively figure out the problem.
For context: My Jenkins server is running on my Mac at the moment. I have a Jenkins user with a workspace on my local machine. I'm also running macOS Sierra and I'm not sure if there could be any permissions issues with the test-reports folder. I see that the folder is being created but no xml file is ever placed inside of it.
If I remove the Publish JUnit test report result then my project will build successfully.
Value on Test report XMLs field (Publish JUnit test result report option) seems to be correct. If you don't have any xml file inside this directory after your build, the problem is inside your test (and generation of xml junit result file), not in Publish JUnit test result report configuration.
Can you be sure that your unit test generate result inside xml file, with Junit format?
Environment
I'm currently trying to run JavaFX GUI tests via xvfb on multiple environments on Travis CI. I'm using Gradle to run these tests while using the TestFX and NestedRunner testing frameworks to write them. Before running the tests, export DISPLAY=:99.0 is called.
Context
There are times when the build succeeds and other times when it fails. However, I've noticed that Gradle outputs a single line that I can use to predict when the build will succeed or fail.
Before that line appears, one will see the following in the Travis CI log:
:richtextfx:compileJava
:richtextfx:processResources
:richtextfx:classes
:richtextfx:compileTestJava
:richtextfx:processTestResources
:richtextfx:testClasses
After that, one of two lines appears that predicts whether the build will succeed/fail:
on success: :richtextfx:testXlib: extension "RANDR" missing on display ":99.0".
on failure: :richtextfx:test
My Question
Why does Gradle change the test task to testXlib task? What are the inner mechanisms that handle this? And what does it all mean?
Gradle for sure does not do this. I've never heard of a task called testXlib and also the complete Gradle source does not contain this character sequence.
Either your build script does this, or some plugin you apply, or an init script that is applied by Travis CI.
Try to increase the logging level to debug and also add a call to tasks --all, maybe that will shed some light.
I use Jenkins to run regression periodically
I have java-maven project with 'ATC.properties' where I can choose browser, environment etc. by uncommenting appropriate one
#### browser ######
browser.name=firefox
#browser.name=chrome
#browser.name=ie
So I have to commit it, push and only after that job on Jenkins will run build with chosen parameters in 'ATC.properties' as well
How can I make my maven project read parameters from parametrised Jenkins build.
Can any one give me some example with browser ?
Do I have to use another one '.properties' file with described variables
like
browser.name=${browser.name} ...
in my project ?
Parameters defined in Jenkins will be expanded at run in Maven Build , Below process does not require additional property file :
Define jenkins choice parameter :
browser_name
Provide all your Browsers options as choices and select the required option at run time.
Now replace your pom.xml with ${browser_name} where you required the option of reading browser value instead of reading value from property file.
pass parameter at run time as below
mvn clean install -Dbrowser_name=%browser_name% [incase of windows]
mvn clean install -Dbrowser_name=$browser_name [incase of linux]
I have 3 Jenkins job. Below are the name of those Jenkins job:
test_existing_api
test_others_api
test_new_api
I have a config file in java project which have 3 different configuration. I want to pick the configuration depend upon Jenkins job. So first I want to check which Jenkins job is executing and then I will take configuration according to that job. That configuration will further require in java code.
Please help me to understand how can I check which Jenkins job is executing now in Java.
Assuming you want to get this data within the job that is executing, see manual entry:
Jenkins Set Environment Variables
When a Jenkins job executes, it sets some environment variables that you may use in your shell script, batch command, Ant script or
Maven POM 1. The following table contains a list of all of these
environment variables.
Environment Variable Description
BUILD_NUMBER The current build number, such as "153"
BUILD_ID The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss)
BUILD_URL The URL where the results of this build can be found (e.g. http://buildserver/jenkins/job/MyJobName/666/)
NODE_NAME The name of the node the current build is running on. Equals 'master' for master node.
JOB_NAME Name of the project of this build. This is the name you gave your job when you first set it up. It's the third column of the Jenkins Dashboard main page.
BUILD_TAG String of jenkins-${JOB_NAME}-${BUILD_NUMBER}. Convenient to put into a resource file, a jar file, etc for easier identification.
JENKINS_URL Set to the URL of the Jenkins master that's running the build. This value is used by Jenkins CLI for example
EXECUTOR_NUMBER The unique number that identifies the current executor (among executors of the same machine) that's carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
JAVA_HOME If your job is configured to use a specific JDK, this variable is set to the JAVA_HOME of the specified JDK. When this variable is set, PATH is also updated to have $JAVA_HOME/bin.
WORKSPACE The absolute path of the workspace.
SVN_REVISION For Subversion-based projects, this variable contains the revision number of the module. If you have more than one module specified, this won't be set.
CVS_BRANCH For CVS-based projects, this variable contains the branch of the module. If CVS is configured to check out the trunk, this environment variable will not be set.
GIT_COMMIT For Git-based projects, this variable contains the Git hash of the commit checked out for the build (like ce9a3c1404e8c91be604088670e93434c4253f03) (all the GIT_* variables require git plugin)
GIT_URL For Git-based projects, this variable contains the Git url (like git#github.com:user/repo.git or https://github.com/user/repo.git)\\
GIT_BRANCH For Git-based projects, this variable contains the Git branch that was checked out for the build (normally origin/master)
Sorry about bad formatting (SO doesn't support nice tables), but you should be able to retrieve these variables with System.getEnv(). This means you don't need to add anything to your Jenkins configuration, just read from java what it already sets.
http://<Jenkins_server>/job/<Job_name>/lastBuild/api/xml?depth=1
Above url will give you the xml structured data, in which you can check <building>false</building> tag value from your java code by parsing the xml.
If value is true than jenkins job is running at the time.
To check which of given three job is running, you can check the status of each job by parsing xml in java code for each job and get configuration file of running job.
P.S. : Replace the place holders in url with applicable data. <Jenkins_server> and <Job_name>
You could pass a system property from the job to the JVM when launching the project:
...whatever... -Dconfig=test_existing_api
and retrieve it in your classes with:
System.getProperty("config")
We have Jenkins installed using GitPlugin to pull branches and merge them, as described in the GitPlugin Wiki. However, when the merge fails there's no output saying why it failed, just that it didn't merge cleanly:
<snip>
Seen branch in repository origin/HEAD
Seen branch in repository origin/labs/intro
Seen branch in repository origin/master
Commencing build of Revision 620c4373792b8cef6a3992b6676892479ed379b0 (origin/REV_4/REV-1234)
Merging Revision 620c4373792b8cef6a3992b6676892479ed379b0 (origin/REV_4/REV-1234) onto REV_4/integration
ERROR: Branch not suitable for integration as it does not merge cleanly
[JaCoCo plugin] Collecting JaCoCo coverage data...
<snip>
I can't duplicate this behavior locally. It has something to do with the Git line ending settings.
Can anybody tell me how to squeeze more information out of Jenkins and the GitPlugin, so I can tell what files are failing?
There probably isn't a way, since there's an open issue about it, and also by looking at the source code at least I don't see exception details recorded anywhere. They're lost.
Some options what you could do:
merge the branch yourself and see if it helps
make a fork of the plugin that saves the information somewhere or outputs it or
run Jenkins using remote debugger, having a breakpoint at that point in code.
There are instructions here to run Jenkins with a debugger:
Add the following to the JENKINS_JAVA_OPTIONS variable (separated by
spaces, surrounded by quotes):
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5678
So the full line may look something like:
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -DXX:MaxPermSize=512m -DXX:+HeapDumpOnOutOfMemoryError -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=0"
Obviously change the port from 5678 to something else if you need.
GIT Plugin prompts this error when there are file conflicts after git merge.
try locally merging both the branches and you can see.
One solution that can be used here is to perform git merge using ours/theirs strategies
git checkout master
git merge -X ours REV-1234
This will allow you to keeps current branch file-revisions for conflicting files.
git checkout master
git merge -X theirs REV-1234
This will allow you to keeps remote branch file-revisions for conflicting files.