Jenkins pipeline with a sbt project - scala

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.

Related

Jenkins - Get System Variables in which Jenkins is installed for Flutter Build

I want to build a flutter application using jenkins.
But in the pipeline script, so I installed jenkins in my system.
For building the app, I created a job and a pipeline. Inside the pipeline I want to run the commands like 'flutter devices, flutter build etc', is it possible. jenkins is not able to recognize these commands.
My shell can find those commands and build the app.
what is going wrong.
Yes you can. Try setting your PATH like below within your pipeline.
environment {
PATH="FLUTTER_PATH:${env.PATH}
}
Or
steps {
withEnv(["PATH+FLUTTER=FLUTTER_PATH"]) {
echo "PATH is: $PATH"
sh 'flutter'
}
}

Karate 1.0.1 Upgrade [duplicate]

I have recently upgraded to version 1.0.0 from 0.9.6 and noticed that the generated karate-summary.html file, it doesn't display all the tested feature files in the JUnit 5 Runner unlike in 0.9.6.
What it displays instead was the last tested feature file only.
The below screenshots are from the provided SampleTest.java sample code (excluding other Tests for simplicity).
package karate;
import com.intuit.karate.junit5.Karate;
class SampleTest {
#Karate.Test
Karate testSample() {
return Karate.run("sample").relativeTo(getClass());
}
#Karate.Test
Karate testTags() {
return Karate.run("tags").relativeTo(getClass());
}
}
This is from Version 0.9.6.
And this one is from Version 1.0.0
However, when running the test below in 1.0.0, all the features are displayed in the summary correctly.
#Karate.Test
Karate testAll() {
return Karate.run().relativeTo(getClass());
}
Would anyone be kind to confirm if they are getting the similar result? It would be very much appreciated.
What it displays instead was the last tested feature file only.
This is because for each time you run a JUnit method, the reports directory is backed up by default. Look for other directories called target/karate-reports-<timestamp> and you may find your reports there. So maybe what is happening is that you have multiple JUnit tests that are all running, so you see this behavior. You may be able to over-ride this behavior by calling the method: .backupReportDir(false) on the builder. But I think it may not still work - because the JUnit runner has changed a little bit. It is designed to run one method at a time, when you are in local / dev-mode.
So the JUnit runner is just a convenience. You should use the Runner class / builder for CI execution, and when you want to run multiple tests and see them in one report: https://stackoverflow.com/a/65578167/143475
Here is an example: ExamplesTest.java
But in case there is a bug in the JUnit runner (which is quite possible) please follow the process and help the project developers replicate and then fix the issue to release as soon as possible.

How to get a Chutzpah Test Adapter to run my QUnit tests on an Azure DevOps pipeline build?

It just works on my machine -
Prior to using Azure DevOps, I simply installed this Chutzpah VSIX 'Test Adapter' add-on in order to run my QUnit tests. My test.js uses Chutzpah's reference syntax.. so Chutzpah will surface the test in the IDE's Test Explorer and I could run them like any other.
Azure Pipeline Docs - says right here that their VSTest#2 task runner supports running Chutzpah unit tests:
Use this task in a build or release pipeline to run unit and functional tests (Selenium, Appium, Coded UI test, and more) using the Visual Studio Test Runner. Other than MSTest-based tests, test frameworks that have a Visual Studio test adapter, such as xUnit, NUnit, Chutzpah, can also be executed.
But my QUnit / Chutzpah tests aren't discovered - if I upload this solution stack to an Azure DevOps repo, and use the default YAML for ASP.NET.. it discovers several unit tests and runs them successfully but none of my javascript/QUnit tests
I'm guessing that my Chutzpah VSIX add-ons are not present on the Azure DevOps build agent machine and I need to do something to make it work - but, what? I'm not currently using the Chutzpah nuget pkg - should I?
Update...
According to this Art of Simplicity blog post I do need to install the Chutzpah NuGet package.
This NuGet package contains all required DLL’s and tooling to be able to run your JavaScript tests. By using this approach you don’t need to install the Chutzpah test adapter on your build server or specify the location of your test adapter. The TFS Build testing tools will automatically detect the required DLL’s and load the test adapter for you.
I'm new to the world of Azure DevOps (and it's predecessors) and didn't adjust my Google-fu to incorporate terms like 'TFS' - so maybe I need to start searching based on that.
Update...
Per the blog post above, I've now added a chutzpah.config file in the root of my web project (it's not in the root of my repo .. my repo has several solutions in it nested at various levels). Still no luck getting it to build on the pipeline server
The key for me was that I had to add the Chutzpah NuGet package to my web project, and then tell the build agent / test runner where to find that Chutzpah 'stuff' (see pathtoCustomTestAdapters switch in the yaml below) more here
Here's my .yml file that worked for me:
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
testAssemblyVer2: '$(Build.SourcesDirectory)/MyApp/trunk/MyWebAppProject/Scripts/tests/test**.js'
pathtoCustomTestAdapters: '$(Build.SourcesDirectory)/MyApp/trunk/packages/Chutzpah.4.4.3/tools/'
In spite of being told in some places to add a .runsettings file, this did not seem to work for my Azure DevOps build agent.. it actually confused it!
FWIW - This is the chutzpah.json I put in the root of my web project (which is not the root of my repo)
{
"Framework": "qunit",
"FrameworkVersion": "1",
"TestHarnessLocationMode": "TestFileAdjacent",
"References": [
{
"Path": "Scripts/qunit.js",
"IsTestFrameworkFile": true
},
{
"Path": "Content/qunit.css",
"IsTestFrameworkFile": true
}
],
"Tests": [
{
"Path": "Scripts/tests/",
"ExpandReferenceComments": true,
"Excludes": [ "fake_razor.js", "fake_razor_search.js","MyCorp.Spa.Routing.Callbacks.js" ]
}
]
}
I don't know if adding this .json was critical to my success or not.

Executing tests in another build.gradle project

I am finishing a Continuous Integration system with Jenkins and Gradle for a REST service. It will build the App and dependent sub-libraries, build a Docker, start main docker and secondary ones (database, ...) all in Gradle.
As it is a REST service I have a separate project that executes the REST tests completely from outside my project just as it is a REST client, and works ok...
Once my project is built and everything running I need to execute the build in the other project (which is just for tests) as a subproject, and wether it passes or not the tests I want to continue the main script as Dockers need to be stopped and deleted. What is the best approach for this?
Thanks
You just need to create a task with type: GradleBuild in parameter
Example:
task buildAnotherProjectTask(type: GradleBuild) {
buildFile = '../pathToBuildFileInTheOtherProject/build.gradle'
tasks = ['build'] // You can run any task like that
tasks = ['test']
}
and to run it u can use the following command
gradle buildAnotherProjectTask
This is worked with me when i tried it.
Hope my answer will help :)

Bamboo deployment - add a new environment to every deployment projects

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