‘Jenkinsfile’ not found - jenkins

I try to use Jenkinsfile for executing build.ps1 file. However, when I scan multibranch-pipeline, I see Does not meet criteria log. Why Jenkins cannot find file. My repo url is this.
Jenkins version : 2.138.3
Jenkinsfile is:
#!groovy
node {
stage ('Checkout') {
checkout scm
}
stage('Check Env Parameters'){
echo "Branch Name : ${env.GIT_BRANCH}"
echo "Octo Server Address : ${env.octoServer}"
}
stage('Run Cake') {
powershell -File build.ps1 -projectName="Jenkins_PowerShell_Cake_Tutorial" -branchName=${env.GIT_BRANCH} -octoServer=${env.octoServer} -octoApiKey=${env.octoApiKey}
}
}
Jenkinsfile's type is not txt
Jenkin Log:
Jenkins Configuration :

The Jenkinsfile in your repo is named .Jenkinsfile (with a dot as first character). Either rename the file or configure the script path with the dot.

Check Jenkinsfile path if not on the same level provide a relative path. This worked for me.

There is also a bug in Jenkins related to this issue:
https://issues.jenkins-ci.org/browse/JENKINS-54126

Related

Jenkins build failed due to command not being recognized

I have this build error saying pandoc command is not recognize, when I build my pipeline on Jenkins :
But when I run the exact same command using cmd.exe from the same repository it works perfectly :
So what's wrong here, my command pandoc is well installed and can perfectly be used from cmd.exe, why doesn't it works from Jenkins ?
Here is my Jenkins code (the part causing the error is in the "Build" stage):
pipeline {
agent any
stages {
stage('Prerequisites') {
steps {
//bat 'RMDIR C:\\wamp64\\www\\html\\doc'
bat 'MKDIR C:\\wamp64\\www\\html\\doc'
}
}
stage('Build') {
steps {
bat 'pandoc -s C:\\wamp64\\www\\index.md -o C:\\wamp64\\www\\index.html'
bat 'pandoc -s C:\\wamp64\\www\\index.md -o C:\\wamp64\\www\\index.docx'
}
}
stage('Deploy') {
steps {
bat 'COPY C:\\wamp64\\www\\index.html COPY C:\\wamp64\\www\\html\\index.html'
bat 'COPY C:\\wamp64\\www\\index.docx COPY C:\\wamp64\\www\\html\\doc\\index.docx'
}
}
}
}
Thanks for helping.
Jenkins doesn't automatically take your Windows (path) environment variables. Instead, what you need to do is to go to Jenkins -> Configure System -> Global properties -> Environment variables and add a new variable called Path. For the value, set $Path, and your path variables should start getting registered.
The issue has been discussed extensively in this question.

Jenkins pipeline script to publish into Jfrogartifactory

I am trying to write a pipeline script to publish *.war/*.jar file to JFrogArtifactory. I don't find any syntax for the same.
Anyone can help me out on the same.
please help me with a sample script.
JFrog has a dedicated GitHub repository with many examples for such cases.
There are Jenkins Pipelines examples there.
First, you must install Artifactory Plugin and config it in Jenkins server.
Refer: https://www.jfrog.com/confluence/display/JFROG/Configuring+Jenkins+Artifactory+Plug-in
And then try add below script to Jenkinsfile:
script {
def server = Artifactory.server '<artifactory id>'
def uploadSpec = '''{
"files": [{
"pattern": "<name of war or jar file>",
"target": "<artifactory repo>/path-to/war-or-jar/file/in-Artifactory"
}]
}'''
server.upload(uploadSpec)
}
Don't forget replace <artifactory id> <name of war or jar file> and <artifactory repo>/path-to/war-or-jar/file/in-Artifactory
More information: https://www.jfrog.com/confluence/display/JFROG/Declarative+Pipeline+Syntax
The scripted pipeline syntax for deploying war files to JFrog artifactory is :
env.ARTIFACTORY = 'True'
if(env.ARTIFACTORY == 'True')
{
stage('Deploying to Artifactory')
{
FAILED_STAGE = env.STAGE_NAME
bat 'mvn deploy'
}
}
Note :
1.) 'bat' command is for Windows batch file. If you're using Linux, replace 'bat' with 'sh'
2.) env.ARTIFACTORY is used to give you control over whether or not you want to execute this particular stage in your pipeline job. if you don't want this stage to execute, simply set env.ARTIFACTORY = 'False'
3.) Also note, you've to configure JFrog in : Manage Jenkins -> Configure system -> JFrog Platform Instances
4.) Include JFrog in your pom.xml file under distributionManagement tag.

How to use inject environment variables (Properties File Path) in Jenkins Pipeline

Want to use the below functionality(shown in image link) in Jenkins as code, but i'm failing to do, kindly help me replicate the functionality in the image to groovy script
stage ('Build Instance') {
sh '''
bash ./build.sh -Ddisable-rpm=false
'''
env "/fl/tar/ver.prop"
}
Jenkins GUI usage of Env Inject
Got a simple workaround :
script {
def props = readProperties file: '/fl/tar/ver.prop' //readProperties is a step in Pipeline Utility Steps plugin
env.WEATHER = props.WEATHER //assuming the key name is WEATHER in properties file
}

How to load a variable within a pipeline using a property file from another freestyle project?

I have a Jenkins "freestyle" project which triggers a "pipeline" project (in fact my "freestyle" project is mentionned as a trigger in "Build Triggers" step of the pipeline project).
How could I grab values of variables from a ".properties" file created by each build of the "parent/freestyle" project?
Currently I have checked "archive artifacts" on the "parent/freestyle" projet and add following code to my "child/pipeline":
node
{
load "${WORKSPACE}/variables.properties"
echo "${PARAM_FROM_TRIGGER}"
}
pipeline
{
agent any
stages
{
stage('STEP1')
{
steps
{
sh '''
#!/bin/bash
echo 'STEP 1'
'''
}
}
}
}
I encounter an exception after the "child/pipeline" build:
java.nio.file.NoSuchFileException:
/var/lib/jenkins/workspace/my_pipeline/variables.properties
How could I load values from my property file?
Since you're already archiving the .properties file, I think you're looking for the Copy Artifact Plugin.
You can use the command:
copyArtifacts(projectName: 'sourceproject');
to copy the artifacts from parent/freestyle into the workspace of child/pipeline.

How to set environment PATH in Jenkins Declarative Pipeline bat block

I'm trying to set the environment PATH variable in a Jenkins Declarative Pipeline and am trying to use the same in a bat block on a windows machine. (I'm trying to modify the path so that I can use the same to call an executable without explicitly specifying the path.)
The path does not get passed to the bat block for some reason.
Any pointers to what could be the issue is highly appreciated from all you experienced developers out there. Thanks in advance!
Following is my code.
pipeline {
agent { label 'docker' }
environment {
PATH = "/hot/new/bin:$PATH"
}
stages {
stage ('build') {
steps {
echo "PATH is: $PATH"
bat """
echo PATH is: %PATH%
"""
}
}
}
}
Output is as follows:
PATH is: /hot/new/bin:blah:blah:my_env_path_content_remianing
PATH is: blah:blah:blah:my_env_path_content_remianing
What about using this syntax to make groovy able to interpolate the variable ?
bat """
echo PATH is: ${env.PATH}
"""
Or like this:
bat "echo PATH is: ${env.PATH}"

Resources