go: not found in declarative Jenkinsfile - docker

I have Jenkins running on Docker and I have the following Jenkinsfile on github
node {
def root = tool name: 'Go 1.12.6', type: 'go'
ws("${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/src/github.com/project/repo") {
withEnv(["GOROOT=${root}", "GOPATH=${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/", "PATH+GO=${root}/bin"]) {
env.PATH="${GOPATH}/bin:$PATH"
stage('Clone repository') {
checkout scm
}
stage('Test repo') {
sh 'go test -v'
}
stage('Build image') {
app = docker.build("docker/repo")
}
stage('Push image') { */
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
app.push("${env.BUILD_NUMBER}")
app.push("latest")
}
}
}
}
}
But no matter what I try I get the following error:
+ go version
/var/jenkins_home/jobs/repo/builds/45/src/github.com/project/repo#tmp/durable-00e72894/script.sh: line 1: go: not found

Jenkins reboots might just fix it

Related

Jenkins No such property: dockerImage error when trying to deploy image to DockerHub

Hi I have set up a pipeline that pulls from Github when there's a commit and publishes an image to Dockerhub. My Pipeline script is as follows:
pipeline {
environment {
registry = "momo979/purple-beard-team-2"
registryCredential = 'dockerhub'
dockerImage= ''
}
agent any
stages {
stage('Cloning Git') {
steps {
git 'https://github.com/Momo979/JenkinsTest.git'
}
}
stage('Building image') {
steps{
script {
docker.build registry + ":$BUILD_NUMBER"
}
}
}
stage('Deploy Image') {
steps{
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Remove Unused docker image') {
steps{
sh "docker rmi $registry:$BUILD_NUMBER"
}
}
}
}
The image gets built ok but during the deploy phase I am getting the following message which causes everything to fail.
"groovy.lang.MissingPropertyException: No such property:
dockerImage for class: groovy.lang.Binding at
groovy.lang.Binding.getVariable(Binding.java:63)"

Jenkins MultiBranch Pipeline: Select to build only 2 specific branches

I have a Jenkins MultiBranch project and I want the test circle to run only on two specific branches on master and on dev. I tried to add on all stages the following
when { anyOf { branch 'master'; branch 'dev' } }
but the only thing I managed to achieve was to deactivate all branch runs
Here is my full pipeline Jenkinsfile
pipeline {
agent any
triggers {
cron('H 0 * * *')
}
options {
disableConcurrentBuilds()
}
stages {
stage('Prepare env') {
when { anyOf { branch 'master'; branch 'dev' } }
steps {
sh 'rm -rf venv'
sh 'rm -rf "${WORKSPACE}/uploads"'
sh 'rm -rf "${WORKSPACE}/downloads"'
sh 'mkdir "${WORKSPACE}/uploads"'
sh 'mkdir "${WORKSPACE}/downloads"'
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')
{
sh 'docker kill $(docker ps -q)'
sh 'docker rm $(docker ps -a -q)'
sh 'docker volume rm $(docker volume ls -q)'
}
}
}
stage('Start Services') {
when { anyOf { branch 'master'; branch 'dev' } }
steps {
}
}
stage('Test Common') {
when { anyOf { branch 'master'; branch 'dev' } }
steps {
}
}
stage('Test Validations') {
when { anyOf { branch 'master'; branch 'dev' } }
steps {
}
}
stage('Test CSV Issuance') {
when { anyOf { branch 'master'; branch 'dev' } }
steps {
}
}
stage('Test XLS Issuance') {
when { anyOf { branch 'master'; branch 'dev' } }
steps {
}
}
stage('Clean env') {
when { anyOf { branch 'master'; branch 'dev' } }
steps {
sh 'rm -rf venv'
sh 'rm -rf "${WORKSPACE}/uploads"'
sh 'rm -rf "${WORKSPACE}/downloads"'
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')
{
sh 'docker kill $(docker ps -q)'
sh 'docker rm $(docker ps -a -q)'
sh 'docker volume rm $(docker volume ls -q)'
}
}
}
}
Can you post the full pipeline you have?
You would use the when block on the stage you want run only on the two branches e.g.
pipeline {
agent any
stages
{
stage ("Testing") {
when {
anyOf {
branch 'master'
branch 'dev'
}
}
steps {
echo "run testing"
}
}
stage ("everything") {
steps{
echo "run on all branches"
}
}
}
}
tested pipeline
pipeline {
agent any
stages {
stage("stage") {
when { anyOf { branch 'master'; branch 'dev' } }
steps {
echo "Hello"
}
}
}
}
on master
[Pipeline] stage
[Pipeline] { (stage)
[Pipeline] echo
Hello
[Pipeline] }
[Pipeline] // stage
On Fish
[Pipeline] stage
[Pipeline] { (stage)
Stage "stage" skipped due to when conditional
[Pipeline] }
[Pipeline] // stage

jenkins pipeline updateGitlabCommitStatus not working

GITLAB_VERSION: GitLab Enterprise Edition 13.9.3-ee
JENKINS_VERSION: 2.263.4
I have crated a jenkins pipeline which is being triggered by change in gitlab, but its not updating gitlab status.
pipeline {
agent any
stages {
stage('cloning from gitlab'){
steps{
git credentialsId: '7d13ef14-ee65-497b-8fba-7519f5012e81', url: 'git#git.MYDOMAIN.com:root/popoq.git'
}
}
stage('build') {
steps {
echo 'Notify GitLab'
updateGitlabCommitStatus name: 'Jenkins-build', state: 'pending'
echo 'build step goes here'
}
}
stage('echoing') {
steps{
echo "bla blaa bla"
}
}
stage(test) {
steps {
echo 'Notify GitLab'
echo 'test step goes here'
updateGitlabCommitStatus name: 'Jenkins-build', state: 'success'
}
}
}
}
its not showing any pipline in gitlab, any suggestions?
I think you miss a "gitlabBuilds" command in an "option" block declaring the steps you will have in your build.
options {
gitLabConnection('xxx-gitlab')
gitlabBuilds(builds: ['step1', 'step2', 'step3'])
}
Then you can reference those steps with the "updateGitlabCommitStatus" but you'd better use the "gitlabCommitStatus" command like this:
pipeline {
agent any
options {
gitLabConnection('xxx-gitlab')
gitlabBuilds(builds: ['step1', 'step2', 'step3'])
}
stages {
stage('step1'){
steps{
gitlabCommitStatus(name:'step1') {
git credentialsId: '7d13ef14-e', url: 'xxxxxxx'
}
} // end steps
} // end stage
stage('step2'){
steps{
gitlabCommitStatus(name:'step2') {
.......
}
} // end steps
} // end stage
}
pipeline {
agent {
label 'agent_gradle'
}
options {
gitLabConnection('Gitlab Jenkins integration API connection test')
gitlabBuilds(builds: ['step1', 'step2'])
}
stages {
stage('Build') {
steps {
gitlabCommitStatus(name: 'step1') {
container(name: 'gradle') {
echo 'Building the application...'
}
}
}
}
stage('Test') {
steps {
gitlabCommitStatus(name: 'step2') {
container(name: 'gradle') {
echo 'Testing the application...'
}
}
}
}
}
}

How to run nodeJS tests with Jenkins

I am learning about Jenkins CI and using pipeline to stage my jobs. I've ran into a halt where my tests aren't running. Please take a look at my "Jenkins Images" link. As you can see its stuck in the --coverage table. Typically, if i were to run my tests on my local machine, i would have to enter wcommand to get node to run all tests; however, i don't think it would be the same in a jenkins setting
Jenkins Image
Jenkinsfile
def gv
pipeline {
agent any
tools {nodejs "node"}
parameters {
choice(name: 'VERSION', choices: ['1.1.0', '1.2.0', '1.3.0'], description: '')
booleanParam(name: 'executeTests', defaultValue: true, description: '')
}
stages {
stage("init") {
steps {
script {
gv = load "script.groovy"
CODE_CHANGES = gv.getGitChanges()
}
}
}
stage("build frontend") {
steps {
dir("client") {
sh 'npm install'
echo 'building client'
}
}
}
stage("build backend") {
steps {
dir("server") {
sh 'npm install'
echo 'building server...'
}
}
}
stage("test") {
when {
expression {
script {
env.BRANCH_NAME.toString().equals('feature-jenkins') && CODE_CHANGES == false
}
}
}
steps {
dir("/client") {
sh 'npm test'
echo 'testing application'
}
}
}
stage("deploy") {
steps {
script {
gv.deployApp()
}
}
}
}
}

How can I use post step in Jenkins pipeline with kubernetes plugin

I try to use the post steps with the Jenkins kubernetes plugin. Does anyone has an idea?
java.lang.NoSuchMethodError: No such DSL method 'post' found among steps
My pipeline:
podTemplate(
label: 'jenkins-pipeline',
cloud: 'minikube',
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
]) {
node('jenkins-pipeline') {
stage('test') {
container('maven') {
println 'do some testing stuff'
}
}
post {
always {
println "test"
}
}
}
}
As of this writing, Post is only supported in declarative pipelines.
You could have a look at their declarative example if you absolutely must use post.
pipeline {
agent {
kubernetes {
//cloud 'kubernetes'
label 'mypod'
containerTemplate {
name 'maven'
image 'maven:3.3.9-jdk-8-alpine'
ttyEnabled true
command 'cat'
}
}
}
stages {
stage('Run maven') {
steps {
container('maven') {
sh 'mvn -version'
}
}
}
}
}
This example shows how to use the post step using the Kubernetes plugin:
pipeline {
agent {
kubernetes {
label "my-test-pipeline-${BUILD_NUMBER}"
containerTemplate {
name "my-container"
image "alpine:3.15.0"
command "sleep"
args "99d"
}
}
}
stages {
stage('Stage 1') {
steps {
container('my-container') {
sh '''
set -e
echo "Hello world!"
sleep 10
echo "I waited"
echo "forcing a fail"
exit 1
'''
}
}
}
}
post {
unsuccessful {
container('my-container') {
sh '''
set +e
echo "Cleaning up stuff here"
'''
}
}
}
}

Resources