I am running jenkins on AWS.
i am running a pipline through a jenkinsfile
node{
stage('Get Git'){
checkout scm
}
stage('Build'){
def mvnHome = tool name: 'mvn', type: 'maven'
sh "${mvnHome} install -DskipTests"
}
stage('Deploy'){
echo "Deploy code here"
}
}
when i run this i get the following errors
(i have left out the git repo stage down below which i working fine)
node{
stage('Get Git'){
checkout scm
}
stage('Build'){
def mvnHome = tool name: 'mvn', type: 'maven'
sh "${mvnHome}/bin/mvn install -DskipTests"
}
stage('Deploy'){
echo "Deploy code here"
}
}
fixed the issue with adding ${mvnHome}/bin/mvn.
Related
I have been trying to do cicd with jenkin pipeline.
I have pull project from git, create jar and run the jar file
Jar file starts the server
and after the server starts the next stage doesn't gets executed
next step is to run karate test cases.
Got stuck here.
This is my pipeline script::
node {
def mavenHome = tool name: "Maven", type: "maven"
stage('git clone') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'b6423164-b18d-43e0-a48f-edd10f90396d', url: 'https://github.com/prajdshakya93/Employee-Record-Managment-System.git']]])
}
stage('build artifact with dependencies'){
bat "${mavenHome}/bin/mvn clean compile assembly:single"
bat("xcopy config.properties C:\\ProgramData\\Jenkins\\.jenkins\\workspace\\ermsPipelinePratice\\target")
}
stage('run jar file'){
dir("target") {
bat "java -jar erms-1.0-SNAPSHOT-jar-with-dependencies.jar"
}
}
stage('run karate'){
bat "${mavenHome}/bin/mvn test -Dtest=KarateTests"
}
}
I am trying to build an application with gradle from within a docker container.
This is my Dockerfile:
FROM openjdk:8-jdk
#install git
RUN apt-get install -y git
RUN git clone https://github.com/SFRJ/yurl.git
#install gradle
RUN wget https://downloads.gradle-dn.com/distributions/gradle-6.5-bin.zip
RUN unzip gradle-6.5-bin.zip
ENV GRADLE_HOME /gradle-6.5
ENV PATH $PATH:/gradle-6.5/bin
#compile and run app
RUN cd yurl
RUN gradle clean build --rerun-tasks --no-build-cache
ENTRYPOINT ["java", "-jar", "/yurlapp.jar"]
Everything goes well until the point where the build command is executed. It throws the following:
Step 9/10 : RUN gradle clean build --rerun-tasks --no-build-cache
---> Running in a25d344c3571
Welcome to Gradle 6.5!
Here are the highlights of this release:
- Experimental file-system watching
- Improved version ordering
- New samples
For more details see https://docs.gradle.org/6.5/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project ''.
> The project name must not be empty. Set the 'rootProject.name' or adjust the 'include' statement (see https://docs.gradle.org/6.5/dsl/org.gradle.api.initialization.Settings.html#org.gradle.api.initialization.Settings:include(java.lang.String[]) for more details).
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
ERROR: Service 'yurlapp' failed to build: The command '/bin/sh -c gradle clean build --rerun-tasks --no-build-cache' returned a non-zero code: 1
I just don't understand what it is. The app builds perfectly fine when I run the same command outside of docker but inside docker fails. This is not a multi module project not sure why it complains about rootProject.
I can confirm that I have a settings.gradle file and inside I have this
rootProject.name = 'yurl'
Also this is my build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.postgresql:postgresql:42.2.11"
}
}
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'org.flywaydb.flyway' version '6.3.0'
id 'nu.studer.jooq' version '4.1'
}
group 'com.javing.yurl'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.8'
implementation 'org.jooq:jooq'
implementation 'org.jooq:jooq-codegen'
jooqRuntime 'org.postgresql:postgresql:42.2.11'
compile 'org.postgresql:postgresql:42.2.11'
implementation 'org.projectlombok:lombok:1.18.8'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'io.vavr:vavr:0.10.2'
implementation 'com.konghq:unirest-java:3.7.00'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.1.0'
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.15.0'
}
jooq {
sample(sourceSets.main) {
jdbc {
driver = 'org.postgresql.Driver'
url = 'jdbc:postgresql://yurldb:5432/yurldb'
user = 'postgres'
password = 'somepassword'
}
generator {
database() {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'public'
includes = '.*'
}
target {
packageName = 'com.javing.yurl'
directory = 'build/generated/java'
}
}
}
}
tasks.generateSampleJooqSchemaSource.with {
def out = new ByteArrayOutputStream()
javaExecSpec = { JavaExecSpec s ->
s.standardOutput = out
s.errorOutput = out
s.ignoreExitValue = true
s.jvmArgs '-Xmx512M'
}
execResultHandler = { ExecResult r ->
if (r.exitValue != 0) {
throw new RuntimeException('jOOQ source code generation failed:\n\n' + out.toString())
}
}
}
flyway {
url = 'jdbc:postgresql://localhost:5432/yurldb'
user = 'postgres'
password = 'somepassword'
schemas = ['public']
locations = ["filesystem:$project.projectDir/src/main/resources/db/migration"]
}
I don't know how to fix this I tried multiple things but nothing worked. I need to build this app from within docker using gradle. I know gradle is installed correctly because if I add the version command (RUN gradle -v) in the Dockerfile, I can see this printed when docker is running:
------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------
Build time: 2020-06-02 20:46:21 UTC
Revision: a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4
Kotlin: 1.3.72
Groovy: 2.5.11
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 1.8.0_252 (Oracle Corporation 25.252-b09)
OS: Linux 4.18.0-25-generic amd64
So my gradle and configuration of gradle seems ok. Also I know the installation of git and the clonning of the project is fine because if I add a RUN ls -s in my Dockerfile it will correctly print all the content of the project.
Something is wrong maybe in the build.gradle or settings.gradle file. Any idea what could be?
Can you try the below Dockerfile as have changed a little bit.
FROM openjdk:8-jdk
#install git
RUN apt-get install -y git
RUN git clone https://github.com/SFRJ/yurl.git
#install gradle
RUN wget https://downloads.gradle-dn.com/distributions/gradle-6.5-bin.zip
RUN unzip gradle-6.5-bin.zip
ENV GRADLE_HOME /gradle-6.5
ENV PATH $PATH:/gradle-6.5/bin
#compile and run app
WORKDIR yurl
RUN gradle clean build --rerun-tasks --no-build-cache
ENTRYPOINT ["java", "-jar", "/yurlapp.jar"]
The problem was, you mentioned a stageRUN cd yurl in which you are changing a directory, which is only valid for that particular stage not for the remaining stages. If you want to use that particular directory for the other stages as well. Use WORKDIR to run that operation which I did above.
P.S.:- If you want to use that directory only for 1 stage, then instead of WORKDIR use RUN cd DIR && ls -lart like command in 1 stage itself.
I have developed a springboot application with Gradle. I have integrated Jenkins and now I'm trying to integrate code coverage into my project. I was using JaCoCo coveralls with Jenkins CI for the purpose.
Gradle plugin
plugins {
id 'com.github.kt3k.coveralls' version '2.10.1'
}
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
getClassDirectories().setFrom(classDirectories.files.collect {
fileTree(dir: it,
exclude: [
'**/BmsService*',
'**/BmsClientWrapper*'])
})
}
And my Jenkins job invokes the following JaCoCo test command.
sh "gradle clean test jacocoTestReport coveralls"
My Jenkins build gets successful and the data is being sent to https://coveralls.io successfully.
My question is: if I do a build with feature branch (except master), in coveralls.io the badge was not displayed properly and even it doesn't show the 'committed by' as well. I'm using GitHub by the way.
Any help would be grateful!
Following are the pipeline jobs I have:
stage('Git checkout') {
deleteDir()
checkout(scm)
}
stage('Build Source code') {
container('gradle-docker') {
sh 'gradle -version'
sh 'gradle clean'
sh "gradle build"
}
}
stage('Code Coverage') {
if('master'.equals(env.BRANCH_NAME)) {
def secrets = [
[$class: 'VaultSecret', path: 'secret/build/credentials', secretValues: [
[$class: 'VaultSecretValue', envVar: 'COVERALLS_REPO_TOKEN', vaultKey: 'coveralls_repo_token']
]]
]
wrap([$class: 'VaultBuildWrapper', vaultSecrets: secrets]) {
container('gradle-docker') {
sh "gradle clean test jacocoTestReport coveralls"
}
}
} else {
println 'Code Coverage is only for the master branch, Skipping for ' + env.BRANCH_NAME
}
}
Based on coveralls documentation you need to configure CI_BRANCH environment details.
And even it's mentioned in coveralls gradle plugin.
You need to extract this information using git commands and populate the required variables.
I just created a Jenkins Pipeline DSL job where I cloned a Java code from SCM and tried to run mvn clean. But the pipeline continuously throwing an error saying:
mvn clean install -Dmaven.test.skip=true -Dfindbugs.skip=true
/var/lib/jenkins/workspace/<project>#tmp/durable-77d8d13c/script.sh: 2:
/var/lib/jenkins/workspace/<project>#tmp/durable-77d8d13c/script.sh: mvn: not found
Seems like it tries to find pom.xml inside the <project>#tmp directory which is empty. Actual code is cloned successfully inside the <project> directory. Below is my Jenkinsfile:
node {
stage ("Clean Workspace") {
echo "${WORKSPACE}"
cleanWs()
}
stage ("Get Code") {
git branch: "${params.branch}", url: 'git#bitbucket.org:xx/xxxxxxx.git'
}
stage ("mvn clean") {
sh "mvn clean install -Dmaven.test.skip=true -Dfindbugs.skip=true"
}
}
I also tried with ${WORKSPACE} env variable but still does not work.
The issue was resolved, I modified the Pipeline DSL jobs by including Maven tool step as:
stage ("mvn clean") {
withEnv( ["PATH+MAVEN=${tool name: 'mvn', type: 'maven'}/bin"] ) {
sh "mvn clean install -Dmaven.test.skip=true -Dfindbugs.skip=true"
}
}
Instead of doing like that you can directly add mvn to path itself. for that, open your ~/.bash_profile and add these lines.
MAVEN_HOME="<path to maven folder>"
export MAVEN_HOME
PATH=$PATH:$MAVEN_HOME/bin
Don't forget to do source ~/.bash_profile to get the changes. This will provide mvn to path so that you can access mvn directly.
So if you do that your code can be now like...
stage ("mvn clean") {
sh "mvn clean install -Dmaven.test.skip=true -Dfindbugs.skip=true"
}
The error message mvn: not found means that mvn command could not be found by Jenkins pipeline.
You should use a withMaven pipeline step to provide a valid maven environnement.
For example :
node {
stage ("Clean Workspace") {
echo "${WORKSPACE}"
cleanWs()
}
stage ("Get Code") {
git branch: "${params.branch}", url: 'git#bitbucket.org:xx/xxxxxxx.git'
}
stage ("mvn clean") {
withMaven {
sh "mvn clean install -Dmaven.test.skip=true -Dfindbugs.skip=true"
}
}
}
Check that Jenkins is properly configured to use maven (Under 'Manage Jenkins > Configure System') and the 'Pipeline Maven Plugin' is installed (Under 'Manage Jenkins > Manage Plugins').
More information here : https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin
my travis ci build keeps failing with,
$ chmod +x /.gradlew
chmod: cannot access ‘/.gradlew’: No such file or directory
The command "chmod +x /.gradlew" failed and exited with 1 during .
I tried all the suggestions, different yml files but cant get rid of this error.
My travis yml is on root directory, the here is my folder structure
root: /src .gitignore .travis.yml
src: /client /server
client: /app /gradle/wrapper build.gradle gradle.properties gradlew gradlew.bat settings.gradle
Here is my travis.yml
sudo: false
language: android
jdk:
- oraclejdk8
android:
components:
- tools
- platform-tools
- tools
# The BuildTools version used by your project
- build-tools-25.0.3
# The SDK version used to compile your project
- android-25
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- addon-google_apis-google-19
before_install:
- chmod +x /.gradlew
script:
- "/.gradlew clean build"
notifications:
email: false
and here is my build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3.3'
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Any suggestions? Thanks
To debug this you could change the before_install section to print current directory and list its contents.
before_install:
- pwd
- ls -la
- chmod +x /.gradlew
Add this .yml file
- name: Check Directory
run: - pwd
- ls -la
- cd android && chmod +x ./gradlew
- name: Build Command
run: cd android && chmod +x ./gradlew