jenkins parameterized build with nexus artifacts - plugins

i am working on Jenkins to create a continuous integration. i want to create a job with parameters which will have a drop down list of artifacts that are stored in nexus and a drop down list of environment that we want those artifacts to be deployed to (web sphere). i am new to Jenkins and would like to get any help that will help me start the job.

You will need Extended Choice Parameter plugin to achieve your goal.
You will have to store the list of artifacts fetched from Nexus in a file. Same goes for the list of environments. These files will then be picked up by the above plugin using the method described in this link. Property File option is what you need to use in the given plugin.

You can also use Dynamic choice parameter,
Then write a groovy script that will take the meatdata out from Nexus,
For me it's working just great.
import groovy.xml.*;
import groovy.util.*;
myUrl = "http://NexusServer.fo.net:8081/nexus/service/local/repositories/repo-name/content/groupID/maven-metadata.xml"
def data = new URL(myUrl).getText()
def dataObj = new XmlParser().parseText(data)
def versions=[]
for (v in dataObj.versioning[0].versions[0].version){
versions.add(v.value()[0])
}
versions.sort(false).reverse()
This is how it looks at the end:

Related

Azure DevOps - Set a Build variable using another variable (nested/composed variables)

In Azure DevOps I have a Pipeline variable "package version" and I set it using 0.1.3$(Rev:.r)-alpha .
I use that variable to replace the "Version" in the .net core project file.
In the Build tasks the dotnet build give me this error:
so I assume the Pipeline variable cannot use a nested variable.
There is a nother way or a different syntax to do it?
[Edit]
The nested variables should work.
I think the error was the dotnet pack using Automatic package versioning set to "Use the build number" that contain the wrong $(rev:.r) (lowercase!).
Using a custom string for Version in the VS project file gives noise on VS (error if the file is open, warning otherwise) and now the Pipeline Build give me an error on dotnet nuget restore because of the invalid Version.
I decided to use a simple clean version, <Version>0.1.2</Version>, that I can choose and document.
Then I want to find a way to read it in the build pipeline and create a custom variable attaching the Build Revision:
0.1.2$(Rev:.r) => 0.1.2.123
That is the result I want.
I found this: https://marketplace.visualstudio.com/items?itemName=tmarkovski.projectversionasvariable
I'm using it with the default settings.
I'm using the variables it creates to compose a new variable, "package version":
and I use that in the nuget pack task:
but it does not work.
The resulting variable still contain "$(Rev:.r)" not parsed.
I'll try to use again the "Automatic package versioning" and create the build number in the Options...
[Edit 2]
Set the build version number in the Pipeline Build Options worked.
It's not the optimal solution because the Build Number is not parsed and looks awful.
[Solution]
$(Rev:.r) is not available outside Build / Options.
I used $(Build.BuildNumber) and I'm able to create a composed variable:
$(Version.MajorMinor).$(Build.BuildNumber)-alpha
Build.BuildNumber is valorized in Build/Options: $(Build.DefinitionVersion)$(Rev:.r)
Version.MajorMinor is created by the Project Version As Build Variable add-on.
I don't know how to obtain the same result without using a third party component.
I'm glad my extension helped and thanks for the nice review. If you want more control and have a little time to spend to play with PowerShell, you can easily achieve what you want in two steps, without using third party extensions.
Read and parse the .csproj file as XML
Set build variables
Here are couple of links on reading XML files and working with build variables, it's actually pretty easy.
https://www.business.com/articles/powershell-read-xml-files/
VSTS: Pass build/release variables into Powershell script task
[xml]$XmlDocument = Get-Content -Path $env:project_file
echo $XmlDocument.Project.PropertyGroup.Version
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=vsts&tabs=yaml%2Cbatch
Write-Host '##vso[task.setvariable variable=package_version;issecret=true]0.1.2.'
Note: my answer wouldn't fit in a comment, I had to post an answer.

How to run multiple projects at a single launch?

I have 4 projects, which are depended each other,I am suppose to run 4 projects one by one.
Is there any way to run as single package?
I suppose that you're running the SOAPUI project using testRunner. Looking at testRunner documentation you can see that it's only possible to pass one project to the call.
However if you're using some automation build tool like gradle you can create and approach creating a custom task to for example make various calls to testRunner passing your projects to execute all sequentially, for more details take a look on this answer.
If you're not using any automation tool or you don't know how to implement it then as a possible workaround you can simply can create a CLI script to do so. For example supposing that you've the SOAPUI_HOME/bin in your classpath on Windows you can create myTestRunner.bat with the follow content:
call testrunner "path/to/your/project1.xml"
call testrunner "path/to/your/project2.xml"
call testrunner "path/to/your/project3.xml"
...
Hope it helps,

How to use Jenkins Build Keeper Plugin

I would like to use the Jenkins 'Build Keeper Plugin' but I don't know how. The plugin site doesn't describe how to use it. Plugin Site
On this page I found the extension points which I would like to use, e.g. the org.jenkins_ci.plugins.build_keeper.KeepFirstFailedPolicy
But in the configuration part of my project, I can't find any place to configure it to use that policy. So where do I have to add it?
Jenkins version is 1.544
Have you tried to open Job configuration page and look for settings ?
For example it is another plugin but it is very similar : Build Discard plugin, may be you will use it for your purposes:
Build discard old build settings
You can configure it in the job under the section Build Environment.
For screenshots see also https://issues.jenkins-ci.org/browse/JENKINS-25293
If used from within a pipeline, it is enough to write
'currentBuild.rawBuild.keepLog(true)'
That is unfortunately not an interface to the plugin, just a jobs setting, but can solve it when You want to keep all builds, or decide within the build if to keep it.

How to use Jenkins Multi-Configuration (Matrix) type Projects?

Jenkins official Wiki page for Matrix projects isn't really helping me; so I have a few questions.
We're trying to build a couple of projects that are all essentially the same, just some are being branded differently for our customers. In other words, the software / tests / etc. are all identical, except for some tweaks to turn BrandA into BrandB (or BrandC, etc.)
I figure I should be using a Matrix project to create builds for BrandA, BrandB, etc. While I haven't figured out all my steps yet (including how to rename executables after they're built) I know that I will need to pass the Brand Name to many of my Jenkins Powershell scripts during the build process, and then use that brand n the script.
How do I get these variables into my scripts? Are they automatically passed in to every build step in Jenkins? What is the variable name to use?
Finally, is there a good resource on building these multi-configuration projects in Jenkins? I can't seem to find anything comprehensive online.
If you usually build the job for BrandA and only occasionally for BrandB and BrandC a matrix project may not be what you want. I recommend, instead, using a parameterized job where the brand is a parameter whose default value is BrandA. If the parameter is named BRAND the parameter is accessible in all of the builds and publish steps with ${BRAND} and as an environment variable as %BRAND%.
I refer you to the parameterized build wiki for more details.
Yes, ${BRAND} and %BRAND% should work fine.
If you're using Maven, ${env.BRAND} does this too.
There's a plugin that you can see all Environment Variables that are available to your job/build.
https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin
I'm not aware of that kind of process but I suggest you tu use the Copy project functionnality.
New Job
Copy From existing job
You will have a copy of your Job and you'll be able to setup easily all specific fields.

How to parameterize Bamboo builds?

Please note, although my specific example here involves Java/Grails, it really applies to any type of task available in Bamboo.
I have a task that is a part of a Bamboo build where I run a Java/Grails app like so:
grails run-app -Dgrails.env=<ENV>
Where "<ENV>" can be one of several values (dev, prod, staging, etc.). It would be nice to "parameterize" the plan so that, sometimes, it runs like so:
grails run-app -Dgrails.env=dev
And other times, it runs like so:
grails run-app -Dgrails.env=staging
etc. Is this possible, if so, how? And does the REST API allow me to specify parameter info so I can kick off different-parameterized builds using cURL or wget?
This seems to be a work around but I believe it can help resolve your issue. Atlassian has a free plugin call Bamboo Inject Variables Plugin. Basically, with this plugin, you can create an "Inject Bamboo Variables from file" task to read a variable from a file.
So the idea here is to have your script set the variable to a specific file then kick off the build; the build itself will read that variable from the file and use it in the grails task.
UPDATE
After a search, I found that you can use REST API to change plan variables (NOT global). This would make your task simpler: just define a plan variable (in Plan Configuration -> tab Variables) then change it every time you need to. The information on how to change is available at Bamboo Knowledge Base