How can I get the Build workspace for a inside job. I have a pipeline which builds jobs in the following:
node('TEST_UST') {
stage('test01') {
build job: 'test01'
}
stage('test02') {
build job: 'test02'
}
}
How Could I get the workspace of job test01?
Related
community.
I would like to run Jenkins job, same job but with diferent maven opts values and in parallel. How can i achieve that? I was trying to use different Jenkins plugins, but with no luck.
Trying to configure pipelines using groovy scripts, but i am so amateur that i can't figure out how to achieve what i want. The goal is to run same jenkins job in parallel, but the only thing that must be different is environment where my tests should run.
Maybe there is already a solution so you could point me to that.
You should be able to use parallel blocks for this. Following is a sample.
pipeline {
agent none
stages {
stage('Run Tests') {
parallel {
stage('Test On Dev') {
agent {
label "IfYouwantToChangeAgent"
}
steps {
sh "mvn clean test -Dsomething=dev"
}
post {
always {
junit "**/TEST-*.xml"
}
}
}
stage('Test On QA') {
agent {
label "QA"
}
steps {
sh "mvn clean test -Dsomething=qa"
}
post {
always {
junit "**/TEST-*.xml"
}
}
}
}
}
}
}
I can't find any example or article how can the continuous delivery pipeline look like when we are using Spring Boot +Docker + Jenkins.
In our new project , We would like to deploy application as docker container in one of our VM’s . I written shell script for this in Jenkins and it's working fine.
The shell script has below steps
checkout branch from git
Zip the project folder
Move it to VM using SCP
Login to VM using ssh
Unzip the project folder
docker-compose stop
docker-compose build
But, I we would like to use Jenkins pipeline . Could anyone help with article or Jenkinsfile steps to achieve the same.
Thanks ,
Madhu.
You can use jenkins declarative pipeline to achive your goal.
Here is one sample example that will give you a little bit idea
pipeline {
agent {
label 'some_build_node'
}
stages {
stage ('Git Checkout') {
steps {
checkout scm
}
}
stage ('Build & Push Docker Image') {
steps {
// You can use this section to build and push image to registry
}
}
stage ('Deploy') {
steps {
// Your steps to perform the deployment here
}
}
}
}
post {
always {
// this block is to perform post build actions such as publishing the test report
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: 'index.html',
reportName: 'Junit Report'
]
}
success {
// action you would want to do upon success. For example notifying about the build on slack/email
}
failure {
// action you would want to do upon failure. For example notifying about the build on slack/email
}
}
}
Here I am using an choice parameters plugin, i need to build the jobs as per the parameter values in choices
for Example:
CHOICE PARAMETER
NAME: Project
VALUE: Job1
Job2
Here Each parameter value has 6 jobs builds need to run in parallel.
import jenkins.model.*
import hudson.model.*
node('') {
if (Project == 'Job1'){
stages ('Parallel-A'){
parallel(firstTask: {
stage ('Parallel-test1'){
build job: 'test1'
}
}, secondTask: {
stage ('Parallel-test2'){
build job: 'test2'
}
})
}
}
if (Project =='Job2'){
stages ('Parallel-B'){
parallel(firstTask: {
stage ('Parallel-test3'){
build job: 'test3'
}
}, secondTask: {
stage ('Parallel-test4'){
build job: 'test4'
}
})
}
}
}
but its not working here, Thanks in advance.
Try $Project
As it was set as parameter, "$" shall be added before the variable.
I am trying to setup Jenkins. I am using the docker image BlueOcean. I am trying to create a Jenkins pipeline using a Job-DSL. When I create the pipeline myself, and run it, it works. But when I run the pipeline created by the Job-DSL, it fails because of maven.
I looked on internet, but I couldn't find a solution proper to my case.
He is the Jenkinsfile
pipeline {
agent {
docker {
image 'maven:3-alpine'
args '-v /root/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests clean package'
}
}
}
and this is the job-DSL
job('PROJ-unit-tests') {
scm {
git('git://github.com/Jouda-Hidri/Transistics.git') { node ->
node / gitConfigName('DSL User')
node / gitConfigEmail('hxxxa#gmail.com')
}
}
triggers {
scm('*/15 * * * *')
}
steps {
maven('-e clean test')
}
}
I'm trying to run the following process in my Jenkinsfile:
Build the app
Trigger deploy of two components to the test environment, in parallel
foo deploy
bar deploy
Run tests on a deployed app
The steps 2 and 3 require locking a resource because I have only one test environment available.
There's no problem to achieve that w/o running step 2 in parallel, however, when I configure Jenkinsfile to run them together I get the following error from Jenkins:
WorkflowScript: 19: Parallel stages or branches can only be included in a top-level stage. # line 19, column 7.
stage('Deploy Foo') {
^
Here's the full Jenkinsfile:
pipeline {
agent any
stages {
stage('Build') {
steps {
powershell(script: '.\\ci\\build.ps1 -Script .\\ci\\build\\build.cake')
}
}
stage('Deploy and run tests') {
when {
branch('develop')
}
options {
lock('test-env')
}
stages {
stage('Deploy') {
parallel {
stage('Deploy Foo') {
steps {
build(job: 'Deploy_Foo')
}
}
stage('Deploy Bar') {
steps {
build(job: 'Deploy_Bar')
}
}
}
}
stage('Run tests') {
steps {
powershell(script: '.\\ci\\build.ps1 -Script .\\ci\\test\\build.cake')
}
}
}
}
}
}
I have also tried a solution with locking test-env resource separately for Deploy and Test stages, however, this increases the risk of race condition when some other running job may wait for that resource and "jump in" between Deploy and Test stages of the current job.
Is there any way to achieve such mix of sequential and parallel stages as described above in Jenkinsfile?