Jenkins pipeline stuck on build job - jenkins

I recently create a new jenkins pipeline that mainly relies on other build jobs. Strange thing is, the 1st stage job gets triggered, ran successfully + Finished with "SUCCESS" state. But the pipeline keeps on loading forever after Scheduling project: "run-operation".
Any idea what mistake i made below?
UPDATE 1: remove param with hard coded advertiser & query
pipeline {
agent {
node {
label 'slave'
}
}
stages {
stage('1') {
steps {
script{
def buildResult = build job: 'run-operation', parameters: [
string(name: 'ADVERTISER', value: 'car'),
string(name: 'START_DATE', value: '2019-12-29'),
string(name: 'END_DATE', value: '2020-01-11'),
string(name: 'QUERY', value: 'weekly')
]
def envVar = buildResult.getBuildVariables();
}
}
}
stage('2') {
steps {
script{
echo 'track the query operations from above job'
def trackResult = build job: 'track-operation', parameters: [
string(name: 'OPERATION_NAMES', value: envVar.operationList),
]
}
}
}
stage('3') {
steps {
echo 'move flag'
}
}
stage('callback') {
steps {
echo 'for each operation call back url'
}
}
}
}
Console log (despite the job was running, the pipeline doesnt seems to know, see log):
Started by user reusable
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/jobs/etl-pipeline/workspace
[Pipeline] {
[Pipeline] stage
[Pipeline] { (1)
[Pipeline] build (Building run-operation)
Scheduling project: run-operation)
...

Related

Using the same node / instance on all build jobs in a Jenkins Pipeline

pipeline {
agent { label 'linux' }
stages{
stage("verify1"){
steps {
script {
build(job: "verfiy1", parameters: [string(name: 'verfiy1', value: "${params.verfiy1}")])
}
}
}
stage("verify2"){
steps {
script {
build(job: "verfiy2", parameters: [string(name: 'verfiy2', value: "${params.verfiy2}")])
}
}
}
stage("verify3"){
steps {
script {
build(job: "verify3", parameters: [string(name: 'verify3', value: "${params.verify3}")])
}
}
}
}
}
=================================================================
Hello
can anyone help me, right now from the above pipeline i am able to build 3 jobs sucessfull but the problem is every single job is executing on new ec2 slave instance instead of the instance where the job has started. I am expecting the output as once the above pipeline starts all the builds in the pipeline must execute on the same node (ec2 instance).
Thanks in advance
You can pass the upstream job's agent node to the downstream job.
Add one more job parameter to accept node
Pass upstream job's agent node via env.NODE_NAME when call build job step
// verify 1 job
pipeline {
agent { label "${params.agentNode}" }
parameters {
string(name: "agentNode",
defaultValue="<give default value in case run it directly>" )
}
}
// upstream job
build(job: "verify1", parameters: [
string(name: 'agentNode', value: "${env.NODE_NAME}"),
string(name: 'verify3', value: "${params.verify3}")
])

How to build pipeline job inside the POST section in Jenkins pipeline

I have a Jenkins pipeline which, among multiple steps should have a final step that should be executed regardless of the status of previous steps. For that to happen, I've tried using post section which looks like this:
pipeline {
agent {
label 'master'
}
stages {
stage('Stage 1') {
steps {
build job: 'stage 1 job', parameters: [
...
]
}
}
stage('Stage 2') {
steps {
build job: 'stage 2 job', parameters: [
...
]
}
}
}
post {
always {
build job: "cleanup", parameters: [
...
]
}
}
}
However, I'm getting following error when trying to execute something like this:
No such DSL method '$' found among steps
Question: Is it even possible to use build job inside post action? If not, what would be good alternative to achieve that "cleanup" job is always executed at the end (regardless of the status of stages above)
Yes, it is possible to use build a job inside post action. Here is the pipeline script:
pipeline {
agent any
stages {
stage('1') {
steps {
script {
echo "Hello"
}
}
}
}
post {
always {
build job: 'schedule-job', parameters: [string(name: 'PLATFORM', value: 'Windows')]
}
}
}
In the above example, I have schedule-job which accepts parameters PLATFORM and it will Always run, regardless of build status
Here is the output:

Matrix pipeline stuck waiting to schedule a build

I have a matrix pipeline that has an agent label with 4 nodes attached to the label. When I try to run my pipeline, the pipeline schedules the job on 4 of the nodes as I wanted but the jobs never end up actually running. They jobs remain scheduled and display the message "Still waiting to schedule task Waiting for next available executor".
How can I fix this issue? I have scoured stack overflow and have yet to come up with any sort of solution.
Update: I am including the pipeline along with a screenshot of some of the configuration
pipeline {
agent none
stages {
stage('Tests') {
matrix {
agent {label 'UH60V && SCADE'}
axes {
axis {
name 'CHOICE'
values 'ADC', 'CDU_C', 'DCU', 'DISP_A_REND', 'DISP_PROC', 'EGI', 'FD', 'FLT', 'FMS_C', 'IFF', 'liblO', 'libNGC', 'libSC', 'MISCMP_MP', 'MISCMP_GP', 'NAV_MGR', 'RADALT', 'SYS', 'SYSIO1553', 'SYSIO429', 'SYSRED', 'TACAN', 'VOR_ILS', 'VPA', 'WAAS', 'WCA'
}
}
stages {
stage("Test") {
steps {
echo "Running ${CHOICE}"
build job: "UH60V_SCADE_Suite_Testing", parameters: [string(name: "SCADE_SUITE_TEST_PROJECT", value: CHOICE), string(name: "SCADE_SUITE_TEST_ACTION", value: "all"), string(name: "CLEARCASE_VIEW_ROOT", value: "myview")]
}
}
}
}
}
}
}
Configuration screenshot

Calling multiple downstream jobs from an upstream Jenkins pipeline job

I have two pipeline based jobs
Parent_Job (has string parameters project1 & project2)
#NonCPS
def invokeDeploy(map) {
for (entry in map) {
echo "Starting ${entry.key}"
build job: 'Child_Job', parameters: [
string(name: 'project', value: entry.key),
string(name: 'version', value: entry.value)
], quietPeriod: 2, wait: true
echo "Completed ${entry.key}"
}
}
pipeline {
agent any
stages {
stage('Test') {
steps {
script {
invokeDeploy(params)
}
}
}
}
}
Child_Job (has string parameters project & version)
pipeline {
agent any
stages {
stage('Test') {
steps {
script {
echo "${params.project} --> ${params.version}"
}
}
}
}
}
Parent job output
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Starting project2
[Pipeline] build (Building Child_Job)
Scheduling project: Child_Job
Starting building: Child_Job #18
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
I expected the downstream job to be called twice, (for project1 and project2) but its invoked only once (for project2)
Is there something obviously wrong with this script?
It seems that the problem with wait: true option enabled for build job step. If you change it to wait: false it will execute 2 times. I tried it on this test pipeline:
#NonCPS
def invokeDeploy(map) {
for (entry in map) {
echo "Starting ${entry.key}"
build job: 'pipeline', quietPeriod: 2, wait: false
echo "Completed ${entry.key}"
}
}
pipeline {
agent any
stages {
stage('Test') {
steps {
script {
def sampleMap = [first_job:'First', second_job:'Second']
invokeDeploy(sampleMap)
}
}
}
}
}

Jenkins pipeline - build a job with default input value from another job

I have a Jenkins Pipeline called pipeline1, described by the following Jenkinsfile:
node()
{
def server
def action
stage("Configuration")
{
def userInput = input(
id: 'userInput', message: 'Let\'s configure this run !', parameters: [
choice(choices: "server1\nserver2", name: "server", description: "Which server do you want to use ?"),
choice(choices: "stop\nstart\nrestart", name: "action", description: "What do you want to do ?")
]);
server = userInput.server;
action = userInput.action;
}
stage("Run")
{
echo(server)
echo(action)
}
}
It asks the user to choice some input in the Configuration stage and just echos them in the Run stage.
I would like to trigger this job from another one and automatically fill the input to avoid human action.
I've tried to use the same syntax we use to build a parametrized job and come to something like this:
node()
{
stage("Run")
{
build job: 'pipeline1', wait: true, parameters: [
[$class: 'StringParameterValue', name: 'userInput.server', value: "server1"],
[$class: 'StringParameterValue', name: 'userInput.action', value: "stop"]
]
}
}
But it doesn't work. It does trigger the pipeline1 job, but it wait for the user to fill the input...
EDIT: I would like to keep the input feature in pipeline1 instead of having a standard parametrized job.
Do you have any idea to achieve this ?
Thanks a lot.
OK so, I have got a complete answer for You. Use properties in pipeline1 and if/else block:
properties([
parameters([
choice(name: 'manually',
description: 'Do you whish to use a user input?',
choices: 'No\nYes')
])
])
node()
{
def server
def action
stage("Configuration") {
if ( params.useIn == 'Yes' || params.manually == 'Yes' ) {
def userInput = input(
id: 'userInput', message: 'Let\'s configure this run !', parameters: [
choice(choices: "server1\nserver2", name: "server", description: "Which server do you want to use ?"),
choice(choices: "stop\nstart\nrestart", name: "action", description: "What do you want to do ?")]
);
server = userInput.server;
action = userInput.action;
} else {
server = params.server
action = params.action
}
}
stage("Run")
{
echo(server)
echo(action)
}
}
Job 2 with little changes:
node()
{
stage("Run")
{
build job: 'pipeline1', wait: true, parameters: [
[$class: 'StringParameterValue', name: 'useIn', value: "No"],
[$class: 'StringParameterValue', name: 'server', value: "server1"],
[$class: 'StringParameterValue', name: 'action', value: "start"]
]
}
}
If You want to run job2, and then use User Input, just change useIn for Yes. So at this moment You can run directly pipeline1 job with User Input:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Configuration)
[Pipeline] input
Input requested
Approved by 3sky
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Run)
[Pipeline] echo
server2
[Pipeline] echo
restart
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
or trigger it by job2, without User Input:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Configuration)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Run)
[Pipeline] echo
server1
[Pipeline] echo
start
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Resources