I have a job (call it BIGJOB) in Jenkins; several of the build steps are to trigger builds on other jobs (call them SMALLJOB) using the Parameterized Trigger Plugin then wait for them to complete. What I need to do is retrieve artifacts from the triggered build on SMALLJOB.
Originally, I thought I could use the Copy Artifact Plugin to retrieve the artifacts from the "last build" of the triggered SMALLJOB. And this does work reliably when there is only one SMALLJOB running at a time.
But I've got multiple BIGJOBs running, all triggering multiple SMALLJOBs so that using the "last build" is unreliable of two SMALLJOBs finish at the same time.
Is there a more reliable way of getting the artifacts from the specific downstream job? If I could just get the build number, I could use curl to get the artifacts.
Just if any (else) stumples accross this question in the future:
When using the Parameterized Trigger Plugin as a build step, then if the trigger is configured with the "Block until the triggered projects finish their builds" enabled, the following Environment variables are made available for further build steps:
LAST_TRIGGERED_JOB_NAME="Last project started"
TRIGGERED_BUILD_NUMBER_{project name}="Last build number triggered"
from version 2.17 onwards
TRIGGERED_JOB_NAMES="Comma separated list of all triggered projects"
TRIGGERED_BUILD_NUMBERS_{project name}="Comma separated list of build numbers triggered"
TRIGGERED_BUILD_RESULT_{project name}="Last triggered build result of project"
TRIGGERED_BUILD_RESULT_{project name}RUN{build number}="Result of triggered build for build number"
TRIGGERED_BUILD_RUN_COUNT_{project name}="Number of builds triggered for the project"
See more info on the plugin website - linked in the question.
Found my own answer. Not as easy as plugin or an already-set variable, but it works.
Use the Jenkins XML API with depth=1 (very import to get the URLs fully traversed and all information available) and XPATH. Here is a sample of the URL I used:
http://jenkins/job/SMALLJOB/api/xml?depth=1&xpath=/freeStyleProject/build[action/cause/upstreamProject="%JOB_NAME%" and action/cause/upstreamBuild=%BUILD_ID%]/number/text()
This would return the build number of the right SMALLJOB (the one started by THIS BIGJOB). Then use that number in http download from Jenkins to get the archived build files.
You may refer to this functions :
Jenkins Build where you can find :
jenkinsapi.api.block_until_complete(jenkinsurl, jobs, maxwait=12000, interval=30, raise_on_timeout=True, username=None, password=None)
jenkinsapi.api.get_artifacts(jenkinsurl, jobid=None, build_no=None, username=None, password=None)
jenkinsapi.api.get_build(jenkinsurl, jobname, build_no, username=None, password=None)
jenkinsapi.api.get_latest_build(jenkinsurl, jobname, username=None, password=None)
jenkinsapi.api.get_latest_complete_build(jenkinsurl, jobname, username=None, password=None)
jenkinsapi.api.get_latest_test_results(jenkinsurl, jobname, username=None, password=None)
jenkinsapi.api.get_nested_view_from_url(url, username=None, password=None)
jenkinsapi.api.get_view_from_url(url, username=None, password=None)
jenkinsapi.api.grab_artifact(jenkinsurl, jobid, artifactid, targetdir, username=None, password=None)
jenkinsapi.api.install_artifacts(artifacts, dirstruct, installdir, basestaticurl)
jenkinsapi.api.search_artifact_by_regexp(jenkinsurl, jobid, artifactRegExp, username=None, password=None)
Related
I'm trying to use Lighhouse CI Action for my Github Actions workflows.
It works well with public pages.
I'm not used to using these tools, merely helping a team get it into their workflow.
My question is, is there a way to run these audits on deployed environments that sit behind authentication?
Or do I need to use the staticDistDir way?
This is primarily in the PR workflows. For when we merge to main and go public, we audit the new page.
- name: Audit URLs using Lighthouse
uses: treosh/lighthouse-ci-action#v7
id: lighthouse_audit
with:
urls: |
https://www.example.com/
budgetPath: ./.github/workflows/budget.json
uploadArtifacts: true
temporaryPublicStorage: true
What I would love to do is have flags for basic auth as well.
I have a bunch of scenarios to automate using protractor. And my client may require an option to execute only specific scenarios out of them.
In my test.js file, my scenarios are listed like this:
var testSuite = {
scenarios: [
{
title: "Scenario - 1",
// My Code
},
{
title: "Scenario - 2",
// My Code
},
{
title: "Scenario - 3",
// My Code
}
]
}
I am trying to know if there is any way to launch a html page, that lists all my scenarios with a checkbox beside every scenario's name. So that I can select only specific scenarios to run using the checkboxes.
My expectation is like this:
<CheckBox> Scenario - 1
<CheckBox> Scenario - 2
<CheckBox> Scenario - 3
So, when I check Scenarios 1 & 3, protractor should run only those scenarios leaving behind the scenario -2.
How do I call that html page with my expectation shown above, when I launch protractor ?
Can anyone provide me an example on how to do this ? as I am completely new to protractor
The way of grouping test scenarios is using Protractor's suites but giving to your client a web interface to run specific suites is another story...
There is currently no web interface to launch Protractor tests and to get there you're going to need quite a few things:
Setup up a Jenkins server with login access for your client/customer.
Signup to Sauce Labs or BrowserStack paid subscriptions and give login access to your client/customer.
Configure Protractor to run against Sauce Labs/BrowserStack.
Create separate Jenkins project for each of your e2e suites so your client can execute tests from Jenkins and then watch live while e2e runs in Sauce Labs/BrowserStack browsers.
What do I need to add to the default html_gmail.jelly script to have it show the classes that were tested including how many tests were ran within each class?
When a Jenkins job is complete you can drill down to the Junit Test Results in an address that looks like:
http://somecompany.jenkins.com/view/App_Automation/job/Application_Under_Test/129/testReport/com.AUT.testing.mobile/
The test results are generated by the build.xml so is it just a matter of pointing to that xml file?
The email-ext page shows a clean example but not the tokens that are used to achieve that: http://wiki.hudson-ci.org/download/attachments/3604514/html.jpg
Currently using the ${FAILED_TESTS} token generates a nice Tested; Failed; Skipped number, but nothing that points to which tests passed/failed/skipped. I would like to show the total number of tests including which tests were actually ran.
Thanks ahead of time
OK I figured out how to display the pass and failed methods by adding var=pass or var=fail to the token of those assignments.
First go to the Jelly script in the this path:
~/.hudson/plugins/email-ext/WEB-INF/classes/hudson/plugins/emailext/templates/automation.jelly
$DEFAULT_SUBJECT (${build.testResultAction?.failCount} ${build.testResultAction?.failureDiffString})
SETTING UP THE CONFIG IN JENKINS
DEFAULT SUBJECT:
$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!
DEFAULT CONTENT:
$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
Check console output at $BUILD_URL to view the results.
Changes:
${CHANGES}
Changes Since Last Success
${CHANGES_SINCE_LAST_SUCCESS}
Failed Tests:
${FAILED_TESTS}
Build Log:
${BUILD_LOG}
Total Amount of Tests:
${TEST_COUNTS, var}
Total = $TEST_COUNTS
Failed = ${TEST_COUNTS,var="fail"}
Total = $TEST_COUNTS
Passed = ${TEST_COUNTS,var="pass"}
Job Description:
${JOB_DESCRIPTION}
Place this in the email job
${JELLY_SCRIPT,template="html-with-health-and-console"}
Note the templates available are noted in the path ~/.hudson/plugins/email-ext/WEB-INF/classes/hudson/plugins/emailext/templates/automation.jelly or create your own.
I've read over the Jenkins site and its JUnit plugin, and for some reason something that is very basic is just not apparent to me.
Jenkins has an Email-ext plugin for sending custom/advanced notification emails whenever a build is ran. In these emails you can place "content tokens" that are runtime variables that get replaced with dynamic values when the email is being generated.
One of these tokens is TEST_COUNTS which allows you to display the number of JUnit tests that ran, or which failed, etc.
How does one go about getting Jenkins to display this information correctly? Is there a plugin I need, and if so, which one? I have my build running JUnit and generating an XML report. I assume Jenkins somehow parses JUnit results out of that XML and uses it to give values to that token.
But on the other hand, I've read "literature" (mailing list posts) that seems to suggest that in order to use that token you need to use Jenkins to run the unit tests, not a junit Ant task from inside your build script.
Can someone clarify this for me and perhaps even set out the "order of operations" for what steps I need to take in order to be able to make use of this token?
It would be supremely useful to get test counts in our build notifications.
Your first explanation is right. You tell Jenkins where to search for JUnit output files, and it parses them to find out the test results:
The test results appear on each project and build page, so as long as you're seeing the correct results there, you should get the correct token replacements in your e-mails
Add something like this to the content in the "Editable Email Notification" configuration:
Total = $TEST_COUNTS
Failed = ${TEST_COUNTS,var="fail"}
I also recommend the Jenkins users mailing list for Jenkins questions, usually helpful.
We have a production job and a nightly job for a project in Hudson. The production job needs to pull off some artifacts from a specific nightly build # (which is provided as parameter). Can anyone help us with a hint on how to achieve this?
The Copy Artifact plugin seems to be capable of doing this.
Another approach could be to fetch the artifact via
http://server/jobs/job1/[build #]/artifacts/
You can use "Build Environment" configuration tools in the job's configuration page. Tick the Configure M2 Extra Build Steps box and add an Execute Shell which grep things from the desired artifact.
We have similar need and use the following system groovy:
import hudson.model.*
def currentBuild = Thread.currentThread().executable;
currentBuild.addAction(new ParametersAction(new StringParameterValue('LAST_BUILD_STATUS', 'FAILURE')));
def buildJob = Hudson.instance.getJob("ArtifactJobName");
def artifacts = buildJob.getLastBuild().getArtifacts();
if (buildJob.getLastBuild().getResult() == Result.SUCCESS && artifacts != null && artifacts.size() > 0) {
currentBuild.addAction(new ParametersAction(new StringParameterValue('VARIABLE_NAME', artifacts[0].getFileName())));
currentBuild.addAction(new ParametersAction(new StringParameterValue('LAST_BUILD_STATUS', 'SUCCESS')));
}
This creates a VARIABLE_NAME with the artifact name in it from ArtifactJobName, which we use since they are all stored in a specific folder. I am not sure what will happen if you have multiple artifacts, but it seems you could get them from the artifacts array.
You could use getLastSuccessfulBuild to prevent issue when another ArtifactJobName is being build at the moment and you get array with null.