I have on-prem TFS 2015, and want to run gitversion, so added step as below:
GitVersion.yml:
mode: Mainline
branches:
feature:
mode: ContinuousDeployment
tag: rc
increment: Minor
source-branches:
- master
fix:
mode: ContinuousDeployment
tag: rc
increment: Patch
regex: ^fix[/-]
bug:
mode: ContinuousDeployment
tag: rc
increment: Patch
regex: '(bug(fix(es)?)?|support)[/-]'
source-branches:
- master
upgrade:
mode: ContinuousDeployment
tag: rc
increment: Major
regex: '(upgrade|major)[/-]'
source-branches:
- master
Build agent is on windows server, installed GitVersion
dotnet tool install --global GitVersion.Tool --version 5.*
But pipeline fails
2022-11-10T11:43:24.9727477Z ##[section]Starting: gitversion/execute
2022-11-10T11:43:24.9934703Z ==============================================================================
2022-11-10T11:43:24.9934703Z Task : Execute GitVersion Task
2022-11-10T11:43:24.9934703Z Description : Easy Semantic Versioning (http://semver.org) for projects using Git
2022-11-10T11:43:24.9934703Z Version : 0.9.15
2022-11-10T11:43:24.9934703Z Author : GitTools Contributors
2022-11-10T11:43:24.9934703Z Help : See the [documentation](https://gitversion.net/docs/) for help
2022-11-10T11:43:24.9934703Z ==============================================================================
2022-11-10T11:43:25.4018670Z ##[error]A supported task execution handler was not found. This error usually means the task does not carry an implementation that is compatible with your current operating system. Contact the task author for more details.
2022-11-10T11:43:25.4018670Z ##[section]Finishing: gitversion/execute
On build machine downloaded gitversion to C:\GitVersion folder then on CI/CD pipeline added task execute command
C:\GitVersion\GitVersion.exe /output buildserver /nofectch
Related
We want to define the project version for our Gradle project during the build of our project in the Jenkins pipeline, which will include a timestamp and a git-commit-id. (20180625180158-b8ad8df0dc0356a91707eaa241de7d62df6a29f2)
void defineVersion() {
sh "git rev-parse HEAD > .git/commit-id"
commitId = readFile('.git/commit-id')
timestamp = getCurrentTimestamp()
version = timestamp+'-'+commitId
}
This function will determine the version I want to publish our artifact with.
Next I use the Artifactory Gradle plugin to publish, but I can't find a way to set/override the project version. I want the jar to be published with version 20180625180158-b8ad8df0dc0356a91707eaa241de7d62df6a29f2
version = defineVersion() // how can we incorperate this version in our gradle build/publish?
gradleBuild = Artifactory.newGradleBuild()
gradleBuild.useWrapper = true
gradleBuild.deployer(
repo: env.BRANCH_NAME == 'master' ? 'libs-releases-local' : 'libs-snapshots-local',
server: Artifactory.server('artifactory-global'))
gradleBuild.run tasks: 'clean build artifactoryPublish'
How can we achieve this? Also I would like to pass other parameters like -x test to the run command to skip tests in this stage.
Apparently you can add parameters throug the switches parameter: https://jenkins.io/doc/pipeline/steps/artifactory/
With this you add the necessary parameters like '-x test -Pversion=' + version
For my use case I added a version property to my build.gradle: version = "${version}" so it can be overridden with the command above.
Does anyone knows for which reasons a SonarQube Scanner analysis could be skipped ?
$ sonar-scanner -X -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN
08:59:10.162 INFO: Scanner configuration file: /home/travis/.sonarscanner/sonar-scanner-2.8/conf/sonar-scanner.properties
08:59:10.166 INFO: Project root configuration file: /home/travis/build/armadito/glpi/plugins/armadito/sonar-project.properties
08:59:10.182 INFO: SonarQube Scanner analysis skipped
The command "sonar-scanner -e -X -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN" exited with 0.
Finally, I found out that travis-ci's sonarqube addon set by itself the following environnment variable :
export SONARQUBE_SKIPPED=true
With the following message :
Skipping SonarQube Scan because this branch is not master or it does not match declared branches
Indeed, I was working on a different branch: DEV.
Thus, the solution is the following, in .travis.yml :
sonarqube:
branches :
- DEV
And in sonar-project.properties :
sonar.branch=DEV
I have added branch under addons in travis.yml and also sonar branch in sonar properties file, but still SonarQube analysis gets skipped. how to fix this?
addons:
sonarqube:
token:
secure: "XXXXXXXXXXXXXXXXXXXXXXXXXX"
branches :
develop
added in travis.yml
and in sonar-project.properties, I have added this key as well
sonar.branch=develop
but travis has always this
$ export SONARQUBE_SKIPPED=true
0.41s$ sonar-scanner
INFO: Scanner configuration file: /home/travis/.sonarscanner/sonar-scanner-2.8/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/........../sonar-project.properties
INFO: SonarQube Scanner analysis skipped
I try to run sonar tests with maven in my Jenkins pipeline project. The documentations says if the sonar is configured globally and you use the withSonarQube step the environment variables with the globally configured sonar properites are injected. So far so good.
http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzingwithSonarQubeScannerforMaven
My pipeline config looks like:
def stash = '********'
def branch = 'dev'
stage('git') {
node {
git branch: branch, credentialsId: 'Buildserver-Private.key', url: stash
}
}
stage('build') {
node {
//....
}
}
stage('sonar') {
node {
withSonarQubeEnv('Sonar') {
sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar'
}
}
}
The build fails because the sonar plugin trys to connect to the default h2 database instead of the configured one. If i check the log, there are no sonar properties passed to maven.
Injecting SonarQube environment variables using the configuration: Sonar
[Pipeline] {
[Pipeline] tool
[Pipeline] sh
[***********] Running shell script
+ cd .
+ /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3_3_9/bin/mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar
[INFO] Scanning for projects...
[...]
[INFO] --- sonar-maven-plugin:3.2:sonar (default-cli) # *******.project.build ---
[INFO] User cache: /var/lib/jenkins/.sonar/cache
[INFO] SonarQube version: 4.5.6
[INFO] Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
12:23:17.971 INFO - Load global referentials...
12:23:18.071 INFO - Load global referentials done: 102 ms
12:23:18.102 INFO - User cache: /var/lib/jenkins/.sonar/cache
12:23:18.109 INFO - Install plugins
12:23:18.176 INFO - Install JDBC driver
12:23:18.183 INFO - Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
Why is my config ignored? What does the documentation mean if it says?
Since version 2.5 of the SonarQube Scanner for Jenkins, there is an
official support of Jenkins pipeline. We provide a 'withSonarQubeEnv'
block that allow to select the SonarQube server you want to interact
with. Connection details you have configured in Jenkins global
configuration will be automatically passed to the scanner.
It seems they are not ...
Has anybody an idea what am I missing?
You are using an old version of SonarQube (4.5.6, the previous LTS) that requires to pass DB connection parameters (URL, login, password) to the scanners - which is a security issue. withSonarQubeEnv does not propagate those settings in order to fix this flaw.
Since SonarQube 5.2, these parameters are no longer required. So you have to use a version that is more recent. I suggest you to upgrade to the latest LTS version of SonarQube (5.6).
I'm puzzled why Gradle's uploadArchive is uploading artifacts from other configurations. My understanding is that when you declare a configuration it will get an upload task for you and when called it will upload the artifacts assigned to its configuration.
That's not the behavior I'm seeing:
apply plugin: 'base'
configurations {
foo
}
task fooIt(type: Zip) {
from 'blah.txt'
baseName 'foo'
}
task barIt(type: Zip) {
from 'blah.txt'
baseName 'bar'
}
artifacts {
foo fooIt
}
repositories {
flatDir {
name 'local'
dirs 'repo'
}
}
uploadArchives {
repositories {
add project.repositories.local
}
}
uploadFoo {
repositories {
add project.repositories.local
}
}
In this example there are no artifacts assigned to the archives configuration but when I call gradle uploadArchives it will upload foo's artifacts.
$ gradle -i uploadArchives
All projects evaluated.
Selected primary task 'uploadArchives' from project :
Tasks to be executed: [task ':fooIt', task ':uploadArchives']
:fooIt (Thread[Daemon Thread 17,5,main]) started.
:fooIt
Skipping task ':fooIt' as it is up-to-date (took 0.008 secs).
:fooIt UP-TO-DATE
:fooIt (Thread[Daemon Thread 17,5,main]) completed. Took 0.017 secs.
:uploadArchives (Thread[Daemon Thread 17,5,main]) started.
:uploadArchives
Executing task ':uploadArchives' (up-to-date check took 0.0 secs) due to:
Task has not declared any outputs.
Publishing configuration: configuration ':archives'
Publishing to Repository 'local'
Published :gradle:unspecified:foo.zip to file:/private/tmp/gradle/repo/foo-unspecified.zip
Published :gradle:unspecified:ivy.xml to file:/private/tmp/gradle/repo/ivy-unspecified.xml
:uploadArchives (Thread[Daemon Thread 17,5,main]) completed. Took 0.017 secs.
BUILD SUCCESSFUL
Two questions out of this:
Why is fooIt getting executed?
Why is uploadArchives uploading foo's artifacts?
Thanks
$ gradle --version
------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------
Build time: 2014-09-08 10:40:39 UTC
Build number: none
Revision: e6cf70745ac11fa943e19294d19a2c527a669a53
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_45 (Oracle Corporation 24.45-b08)
OS: Mac OS X 10.10.2 x86_64
The archives configuration contains all artifacts from all configurations. I believe the confusion comes from the fact that you can also add artifacts directly to the archives configuration if you want. That being the case, the uploadArchives task will always upload all the declared artifacts. If you want to upload a subset of your artifacts then you should call the upload<<ConfigurationName>> task.
I am using jenkins-job-builder to create my pipeline project. But I have a problem with the variables values when I am trying to reuse or propagating.
It is my project configuration:
- project:
name: myproject
git_url: git#gitlabserver.cu:demos-products/myproject.git
jobs:
- '{name}-nfr-smoke-tests':
pipeline-next: '{name}-nfr-smoke-tests'
And here is my job-template:
- job-template:
name: "{name}-nfr-smoke-tests"
node: 'slave1'
scm:
- git:
skip-tag: false
url: 'git#gitlabserver.cu:test-products/{name}-nfr-tests.git'
branches:
- master
wipe-workspace: true
builders:
- shell: |
bundle install
bundle exec cucumber features/smoke.feature
publishers:
- trigger:
project: "{pipeline-next}"
threshold: SUCCESS
Ok, now when I run this configuration in jenkins and I check the job's construction, it says:
No such project ‘{name}-nfr-smoke-tests’. Did you mean ‘myproject-nfr-smoke-tests’?
Why the line: pipeline-next: '{name}-nfr-smoke-tests'doesn't propagates the value of variable name and just used it as a literal string? I am missing something.
You are missing 'name' under 'project' section in your job-template. Append the following lines:
- project:
name: project-name
The purpose of a project is to collect related jobs together, and provide values for the variables in a Job Template.
I found out that Jenkins Job Builder version 0.9.0-0.2 does not propagate the value, but for me version 1.3.0+2015.12.15.git136.959eb4b909-1 did. Perhaps updating your version of Jenkins Job Builder might help?