Bamboo deployment - add a new environment to every deployment projects - deployment

We have a new environment created and we want to configure all Bamboo deployment projects such that the artifact is deployed to that environment. It is too stupid to do it manually by clicking into each of the deployment project and add the new environment - as the only difference is the host name, while all the steps are the same. Is there any smart way to do that?

AFAIK, this is not possible with Bamboo itself (i.e., you need to do this in the UI). If you don't mind a plug-in, you could use our Plan DSL for Bamboo plug-in. Here's how the DSL would look like to accomplish this task (it is basically just Groovy):
['PLANKEY-1', 'PLANKEY-2'].each { planKey ->
project('PROJECTKEY') {
plan(planKey) {
deploymentProject("Deployment Project Name") {
description "Deployment project for plug-in"
environment("Staging") {
description "Your new deployment project"
tasks {
cleanWorkingDirectory("Clean the working directory") {}
artifactDownload("Download release contents") {
artifact("plug-in") {
}
}
}
}
}
}
}
}
You basically just have to iterate through all your plans and add the deployment project with all its components (triggers, tasks, etc.).
Please note that the plug-in is brand new and that our documentation is not as good as we want it to be.
Cheers,
Michael

Related

Is there a way to associate Automated tests to Test Cases in Azure DevOps using VS Code?

I've been looking for an extension for VS Code that will allow the "Associate Test Case" functionality provided with Visual Studio IDE and I have had no luck.
Is there an extension that provides this functionality?
Visual Studio steps:
Open Test Explorer
Right click on a Test Case
Click on Associate To Test Case
Screenshot:
As far as I know, currently there is no such extension provided in the visual studio code to support the "Associate Test Case" function.
You could add your request for this feature on vscode UserVoice site The product team would provide the updates if they view it.
Check this extension that I have created https://github.com/JanuszNowak/janono.ado.testcase.associate.cli
it allows associating in automatic manner.
For now this is CLI, that you can run as vs-code task. Later I will create also dedicated Azure DevOps task. Visual Studio is not needed to run automatic association.
Code sample:
namespace ExampleTestProject
{
[TestClass]
[janono.ado.testcase.associate.Organization("janono-pub")]
public class UnitTest1
{
[TestMethod]
[janono.ado.testcase.associate.TestCase(5)] //<---
public void TestMethod1()
{
//yours test method content
//...
//
}
}
}

Jenkins pipeline with a sbt project

I have to write a pipeline code for jenkins using a sbt project. Normally I use Maven. I can't find the equivalent of withMaven for sbt projects. Do you know what it is?
AFAIK, there's no perfectly simple equivalent, since the sbt-plugin for jenkins haven't been ported to be pipeline-friendly.
The situation resumed in this ticket : https://issues.jenkins-ci.org/browse/JENKINS-42475 is that there's a few possible ways to achieve that.
My prefered (aka the one similar to what we use in prod currently) is the last one :
pipeline {
agent {
docker {
image 'hseeberger/scala-sbt'
}
}
stages {
stage('Test') {
steps {
echo 'Building..'
sh "sbt test"
}
}
}
}
However, feel free to read through the ticket for other options, notably if docker is not an option for you, going for something like https://gist.github.com/muuki88/e2824008b653ac0fc5ba749fdf249616 should be quite ok too.

Using Fabric8's Openshift Client, is there a way I can tell if a Project Name is available, as a regular user?

In the recent versions of OpenShift when you delete a project, the project will be taken off of the project list, but for whatever reason - the namespace will be unavailable until after some time. I imagine it is still cleaning up and/or shutting down resources in the background.
Before, I was using client.projects.list() to get access to the projects, to verify that the new project I wish to create did not already exist. But now a project may not be in this list, but it's name may still be unavailable (if it were recently deleted), thus throwing an error when I submit a new project request for creation (i.e. stating "This name is already in use").
How can I easily verify, as a regular user, if a project name is available for use?
OpenShiftClient can watch the state of the project.
Project project = new ProjectBuilder().withNewMetadata().addToLabels("key", "label").endMetadata().build();
client.resource(project).watch(new Watcher<Project>() {
#Override
public void eventReceived(Action action, Project resource) {
// logic goes here
}
#Override
public void onClose(KubernetesClientException cause) {
}
});

.NET Core App - How to get build number at runtime

I've got a .NET Core MVC app which is built using TFS online, and published to Azure using the Release management stuff in TFS online. All very nice.
What I'd like to do is have my app display the build number somewhere. Doesn't matter where...but for example in a WebAPI endpoint like /api/buildversion.
Can anyone help with how I can get the TFS build number at runtime? When the app is packaged/published is there any file which contains the build number that I can access from the application?
The simple way is that you can store the build number in a file (e.g. appsettings.json), then get this data in app code.
Appsettings.json sample code:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplication1-ab933d83-8f4b-4024-9f3c-1aef5339a8f3;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
"CodeVersion": {
"Num": "#{MyBuildNumber}#"
}
}
Install Replace Tokens extension
Edit your build definition
Click Variables tab and add a variable. (Name: MyBuildNumber, Value:$(Build.BuildNumber))
Add Replace Tokens build step before build step
There is an easier way than adding more plugins and libraries. If you are using the web/app deploy method, expand the File Transforms & Variables
Assuming you want to update say a build number value in your appsettings.json
Then just update the variables setting in your release definition of VSTS
Super easy. This is more or less the same steps in Octopus IIRC.
You need to save the Build Number in your application at compile time.
You can access the build number with $Build.BuildNumber or $Env:BUILD_BUILDNUMBER depending on your environment. I usually write it as a variable into my ApplicationInfo.* with both the version and build number.

jenkins parameterized build with nexus artifacts

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: