Jenkins : Query Consolidated details for current & previous builds - jenkins

How can I Query Jenkins and get below consolidated information?
last 5 build details.
defined xpath parameter values.
Individually I am able to query and get the above details with different URL. Expecting single URL to give consolidated details.
The below Jenkins URL gives me last 5 build details
https://myorg.jenkins/job/myrepo/api/xml?pretty=true&tree=builds[number,url,result]{0,5}
<workflowJob _class="org.jenkinsci.plugins.workflow.job.WorkflowJob">
<build _class="org.jenkinsci.plugins.workflow.job.WorkflowRun">
<number>150</number>
<result>SUCCESS</result>
<url>https://myorg.jenkins/job/myrepo/150/</url>
</build>
<build _class="org.jenkinsci.plugins.workflow.job.WorkflowRun">
<number>149</number>
<result>FAILURE</result>
<url>https://myorg.jenkins/job/myrepo/149/</url>
</build>
<build _class="org.jenkinsci.plugins.workflow.job.WorkflowRun">
<number>148</number>
<result>FAILURE</result>
<url>https://myorg.jenkins/job/myrepo/148/</url>
</build>
<build _class="org.jenkinsci.plugins.workflow.job.WorkflowRun">
<number>147</number>
<result>FAILURE</result>
<url>https://myorg.jenkins/job/myrepo/147/</url>
</build>
<build _class="org.jenkinsci.plugins.workflow.job.WorkflowRun">
<number>146</number>
<result>FAILURE</result>
<url>https://myorg.jenkins/job/myrepo/146/</url>
</build>
</workflowJob>
This jenkins URL gives me the parameter values
https://myorg.jenkins/job/myservices/job/myrepo/150/api/xml?xpath=//parameter[name=%27yaml_data_formatted%27]/value
<value>apim_apim_endpoint="https://na.myorg.com/digital.platform.apimautomation/devops/";apim_token_apiversion="2";apim_token_app_id="25jjg7bggg40378403440";apim_token_app_key="TVDVSs.:/rdFDFEDF%#VFDD";</value>

Related

How to use Atlassian Bamboo variables in Maven pom.xml?

I want to use Atlassian Bamboo to deploy non-Maven artifacts, that is artifacts created outside of Maven in another Bamboo task. So I created a Maven 3.x task and put it after the task that creates the artifacts and put deploy:deploy-file in the Goal box. The goal configuration requires the full path of the file I want to deploy. So I did this...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>deploy-my_artifact-tgz</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<!-- Will this work??? -->
<file>${bamboo.build.working.directory}/dist/my_artifact.tgz</file>
<url>${project.repoUrl}</url>
<repositoryId>${project.repoId}</repositoryId>
<groupId>${project.groupId}.rtim.garner</groupId>
<version>${project.version}</version>
<artifactId>my_artifact</artifactId>
<packaging>tgz</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Can I use the ${bamboo.build.working.directory} to define part of the file path inside the part of the , as I have above? Should I expect Bamboo to substitute this to the correct value?
NOTE: Showing the effective pom in the Bamboo job does not substitute the varables' corresponding value so I can't tell.
I had to pass it the value of the variable. So I have this in my Goal text box of my Bamboo Maven task.
-Dbamboo.build.working.directory=${bamboo.build.working.directory} deploy:deploy-file

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy default-deploy on project

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project.
Failed to deploy artifacts: Could not transfer artifactReturn code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
There was no changes made since last successful build.
I double check settings.xml(username and password).Also check in pom.xml(distribution management)
I working on this issue since last 2 days.I gone through all the forum,nothing works.please help me out.
This error message means your machine is not authenticating correctly to the Nexus machine. The credentials sent to Nexus from Maven are not correct.
When I have gotten this message, I usually have to look in my settings.xml to verify the proper credentials in this part. The username and password have to be the right ones as set in Nexus itself.
<servers>
<server>
<id>nexus-releases</id>
<username>fillin</username>
<password>fillin</password>
</server>
</servers>
I usually go the Nexus GUI and try to log in with those credentials to verify them but it is possible to configure credentials that can publish via mvn but not log into the GUI.
One possible problem is if you are using dependency-management to identify where to deploy in case of "mvn deploy" target. There is a section like this:
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>releases</name>
<url>http://myNexus/more/stuff</url>
</repository>
</distributionManagement>
and the id field has to match the the id on the credentials in the settings.xml. If the ids don't match, you will get this error.
Another possible problem is that if you are using an execution for the maven-deply-plugin in your pom.xml, you might have the configuration property
<repositoryId>nexus-releases</repositoryId>
and again it doesn't match the id in the settings.xml so it fails with your error.
Similarly, if deploying using the command line option on the "mvn" command that looks like this
-DrepositoryId=nexus-releases
doesn't match the id in the settings.xml, again, it won't work.
Following our discussion in the comments section,
try to run this pom.xml
When the mvn goal should be : mvn deploy
The only two things you need is having a pom and passing the arguments:
This is the pom.xml you can use:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hp.Maven</groupId>
<artifactId>Maven-Nexus</artifactId>
<packaging>pom</packaging>
<version>1.0.0</version>
<properties>
<baseNexusURL>${baseNexusURL}</baseNexusURL>
<targetRepositoryID>${repositoryId}</targetRepositoryID>
<package.final.name>${project.artifactId}</package.final.name>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>default-deploy</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>deploy-node-modules-artifact</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${file}</file>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<packaging>${packaging}</packaging>
<generatePom>true</generatePom>
<repositoryId>${targetRepositoryID}</repositoryId>
<url>${baseNexusURL}/content/repositories/${targetRepositoryID}</url>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

liquibase maven plugin disable checksum

I'm using liquibase with maven-3. The first run works as expected. Consecutive runs though (even if the sql files contain changes) fail, as they are viewed as equivalent from liquibase and ignored (checksum).
All the sql actions in my sql scripts have taken into account the previous runs, so I don't want this behaviour. With this setup that you see below, how can I force liquibase to always execute my scripts, no matter the changes?
As you can see below I've already tried setting clearCheckSums as a goal and indeed it clears the hash values, but still no luck (thus commented out).
This is the profile I've created
<profile>
<id>liquibase-executions</id>
<build>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.2</version>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>update-schema</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
<!--<goal>clearCheckSums</goal>-->
</goals>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>${basedir}/src/main/resources/liquibase.sql</changeLogFile>
</configuration>
</execution>
<execution>
<id>update-data</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
<!--<goal>clearCheckSums</goal>-->
</goals>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>${basedir}/src/main/resources/liquibase-populate.sql</changeLogFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
And this is how I execute it
mvn process-resources -Pliquibase-executions -Ddb.url=POSTGRES_IP:5432/POSTGRES_DB -Dliquibase.username=POSTGRES_USERNAME
The Liquibase Maven plugin expects a changelog file, no plain .sql file. This file should contain your changeSets that you want Liquibase to execute. These changeSets can be instructed to be run every time you run Liquibase (by default they're only executed once). So there's no need to tamper with the checksum. For example your changelog file could look something like this:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="your-id" author="msp" runAlways="true">
...
</changeSet>
</databaseChangeLog>
The important part to achieve your intended behaviour is to set the runAlways="true" attribute in your liquibase changeset.

build helper plugin not parsing project version

I have a project where I have a need to break the version number down and access it's component pieces when building a manifest file. After doing some searching around I found the build-helper-maven-plugin and figured my problem was solved. I added the plugin to the master POM, it's shown below.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<propertyPrefix>parsedVersion</propertyPrefix>
</configuration>
</execution>
</executions>
</plugin>
The project version at this point in time is 3.0.0-SNAPSHOT. I wanted to see all the pieces (although in the final version I may not use them all) so I added these lines to my manifest file.
<value name="majorVersion">${parsedVersion.majorVersion}</value>
<value name="minorVersion">{$parsedVersion.minorVersion}</value>
<value name="incrementalVersion">${parsedVersion.incrementalVersion}</value>
<value name="versionQualifier">${parsedVersion.qualifier}</value>
<value name="parsedBuildNumber">${parsedVersion.buildNumber}</value>
After building I get this.
<value name="majorVersion">0</value>
<value name="minorVersion">{$parsedVersion.minorVersion}</value>
<value name="incrementalVersion">0</value>
<value name="versionQualifier">3.00.0-SNAPSHOT</value>
<value name="parsedBuildNumber">0</value>
The value tag is actually an XML tag and there is a closing value tag in the manifest file, I had to remove them since they were messing up the display.
So the incremental version appears to be correct, although I'm not all that confident given that the major version isn't correct, it found no minor version, and the qualifier comes back as the entire version number, rather than just the SNAPSHOT piece i had expected. I can see where a build number of zero would be correct since we don't have what Maven considers a build number.
Any ideas on why the version number doesn't seem to be parsing? Have I implemented this plugin incorrectly?
thanks
steve
Change {$parsedVersion.minorVersion} to ${parsedVersion.minorVersion}
When are you inspecting the property values? Ensure you're doing it after the validate phase in your example, or if you want it on the same phase ensure the build-helper-maven-plugin occurs before the plugin you're using to inspect the property values. If I have this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Major: ${parsedVersion.majorVersion}</echo>
<echo>Minor: ${parsedVersion.minorVersion}</echo>
<echo>Incremental: ${parsedVersion.incrementalVersion}</echo>
<echo>Qualifier: ${parsedVersion.qualifier}</echo>
<echo>BuildNumber: ${parsedVersion.buildNumber}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
after the build-helper-maven-plugin, I see this in the output of mvn validate:
[INFO] --- build-helper-maven-plugin:1.7:parse-version (parse-version) # so-example ---
[INFO]
[INFO] --- maven-antrun-plugin:1.1:run (default) # so-example ---
[INFO] Executing tasks
[echo] Major: 1
[echo] Minor: 0
[echo] Incremental: 0
[echo] Qualifier: SNAPSHOT
[echo] BuildNumber: 0
anew#buddha:~/dev/so-example$ grep "<version>" pom.xml | head -1
<version>1.0.0-SNAPSHOT</version>

Jmeter Reports do not get generated if there are errors if the Jmeter Test executed using Jmeter Maven Plugin

I am running Jmeter tests using Jmeter Maven Plugin. After I run the test I want to generate simple reports that indicate if the tests passed/failed. I referred to
https://stackoverflow.com/questions/4669467/jmeter-how-to-create-summary-report-from-jtl-file?lq=1
for generating the reports. I have added a shell script to generate html reports from the jmeter jtl result files.Then I use the exec-maven plugin to execute the script that in turn generates the html report files.So far Everything works fine. The problem that I am facing is that if one of the Jmeter tests fails then the report isn't generated at all.
So I am assuming that maven exits once it detects error in the test-suites and doesn't execute the exec-maven plugin and hence the shell script isnt called at all.
Can someone give me directions on this? Is there any property in the pom file or any settings that I can try to get around this. Any help would be truly appreciated!
You can set the <ignoreResultFailures> configuration setting to true to make the plugin ignore the failures and continue executing everything else.
+---+
<project>
[...]
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreResultFailures>true</ignoreResultFailures>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
[...]
</project>
+---+

Resources