#jenkins_Unable to get subversion checkout using jenkins in Pipline build - jenkins

i have created a jenkins pipe line build where using below pipline code when i try to build a error appears stating "Checking out http://192.160.142.39/Mobility/branches/AppiumTesting/test.automation at revision '2023-02-20T12:07:18.262 +0530'
Using sole credentials in realm ‘http://192.160.142.39:80 VisualSVN Server’
ERROR: Subversion checkout has been canceled"
i have tried suggestions mentioned in many threads as well , but not able to fix this issue . could you please suggest the issue :-
PipeLine COde:-
pipeline {
agent any
stages {
stage('Checkout') {
steps {
script {
def svnUrl = 'http://192.160.142.39/Mobility/branches/AppiumTesting/test.automation'
def svnCredsId = 'APatil' // ID of the SVN credentials in Jenkins
def workspace = pwd() // current working directory
// Checkout source code from SVN repository
svn url: svnUrl,
credentialsId: svnCredsId,
revision: 'HEAD',
depthOption: 'infinity',
ignoreExternals: true,
changelog: false,
workspaceUpdater: [$class: 'CheckoutUpdater'],
poll: false,
quiet: true,
workspaceUpdaterArguments: [location: workspace]
}
}
}
stage('Build and Package') {
steps {
// Build and package the code into a JAR file
withMaven(maven: 'maven-3.8.2') {
sh 'mvn clean package'
}
}
}
stage('Deploy to Nexus') {
steps {
// Deploy the JAR file to a Nexus repository
nexusPublisher nexusInstanceId: 'nexus',
nexusRepositoryId: 'maven-snapshots',
packages: [[$class: 'MavenPackage', mavenCoords: 'test.automation:core:1.0-SNAPSHOT',
file: 'target/core-1.0.jar']]
}
}
}
}

Related

CICD pipeline to deploy a release build without losing its dependent files

can someone help me to make a pipeline for the below requirement.
Get the Src from team foundation server.
Make the build on local server.
Move that build on client server say 10.10.1.180
Host the file on IIS.
run on specific port.
Any help will be appreciated.
pipeline {
agent any
stages {
stage('Clone Git Repo') {
steps {
git branch: 'newbranch', credentialsId: 'xyz', url: ''
}
}
stage('Navigate to Agent_Frontend') {
steps {
dir('Agent_Frontend') {
bat 'dir'
bat 'npm i --force'
}
}
}
}
}

Jenkins webhook build pull requests from forks

We are using bitbucket-push-and-pull-request plugin in order to build our project. The pipeline is set to checkout the source repo when webhook is triggered and everything works fine, when PR's coming from the origin repo.
When the pull requests comes from forked repo then the problem appear where cannot find the commit because is still in the fork.
Any idea how we can solve it?
Here is a example of the jenkinsfile:
pipeline {
triggers {
bitBucketTrigger credentialsId: 'GIT_CREDS',
triggers: [
[$class: 'BitBucketPPRPullRequestServerTriggerFilter',
actionFilter: [$class: 'BitBucketPPRPullRequestServerCreatedActionFilter',
allowedBranches: ''
]
],
[$class: 'BitBucketPPRPullRequestServerTriggerFilter',
actionFilter: [$class: 'BitBucketPPRPullRequestServerMergedActionFilter',
allowedBranches: ''
]
],
[$class: 'BitBucketPPRPullRequestServerTriggerFilter',
actionFilter: [$class: 'BitBucketPPRPullRequestServerSourceUpdatedActionFilter',
allowedBranches: ''
]
]
]
}
agent any
stages {
stage('Checkout Bitbucket repo') {
steps {
script {
git branch: 'env.CHANGE_BRANCH',
credentialsId: 'GIT_CREDS',
url: env.GIT_URL
}
}
}
stage('Start the build') {
steps {
script {
sh 'echo "BUILD"'
}
}
}
}
}
Here is the LOG:
stderr: fatal: ambiguous argument '0648334d4491907a45a840a7326c3b8f54180144^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
I was able to fix this by adding Refspec in Advanced tab.
The refspec is:

Clone Jenkinsfile by changing default workspace from master to slave

I am working on Jenkins Pipeline Script and I have checked-in my jenkinsfile in Git repository and I need to clone to local work space. But by default its cloning to master (Unix) work space but I need it in slave (Windows) work space.
Is there any plugins to change the default Pipeline Script from SCM work space location to slave?
You can do something like this
pipeline {
agent any
options {
skipDefaultCheckout()
}
stages {
stage('checkout') {
steps {
node('windows') {
checkout scm
}
}
}
}
}
OR
pipeline {
agent 'windows'
stages {
stage('build') {
steps {
// build
}
}
}
}
In my case, the following pipeline configuration skips the default checkout on master, and checkout my code just on Jenkins slave.
node {
docker.image('php7.1.30:1.0.0').inside {
skipDefaultCheckout() // this avoid the checkout on master
stage("checkout"){
checkout scm // here the checkout happens on slave node
}
stage('NPM Install'){
sh label: 'NPM INSTALL', script: "npm install"
sh label: 'GRUNT INSTALL', script: "npm install -g grunt-cli"
}
stage('Executing grunt') {
sh label: 'GRUNT DEFAULT', script: "grunt default"
}
}
}

How to deploy a a java application on a WildFly (Or any App Server) through jenkins groovy script?

I wanted to deploy a java application on a WildFly server or any application server through jenkins script. Can any one help me in providing the syntax or command?
pipeline {
agent any
stages {
stage('Code Checkout') {
steps {
git(url: 'http://github.com/ ', branch: 'master ', poll: true, credentialsId: '', changelog: true)
}
}
stage('Build') {
steps {
withMaven(jdk: 'jdk8', maven: 'mvn3') {
sh 'mvn clean package'
}
}
}
}
Here I want the syntax for deploying application on wildfly or any server.

use the same Jenkinsfile for several github repositories

I have 40-50 github repositories , each repo contain one maven job.
I want to create multibranch pipeline job for each repository.
can I use the same Jenkinsfile for all projects without add Jenkinsfile for each repository. (take it from another SCM repo) ?
I know that I can use shared library to create a full pipeline , but I prefer something cleaner.
To accomplish this, I would suggest to create a pipeline with two parameters and pass the values based on the repo to build. 1) GIT BRANCH - to build and deploy required branch
2) GIT URL - to provide the git URL to checkout the code.
Providing a reference template.
node('NODE NAME')
{
withEnv([REQUIRED ENV VARIBALES])
{ withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'CREDENTIALS ID', passwordVariable: 'PW', usernameVariable: 'USER']])
{ try
{ stage 'Build'
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: gitbranch]], doGenerateSubmoduleConfigurations: false,
extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'CREDENTIALS ID',
url: 'GIT URL']]]
****
MAVEN BUILD
****
stage 'Docker Image build & Push'
*****
DOCKER BUILD AND PUSH TO REPO
*****
}
catch (err) {
notify("Failed ${err}")
currentBuild.result = 'FAILURE'
}
stage 'Deploy to ENV'
*****
DEPLOYMENT TO REQUIRED ENV
*****
notify('Success -Deployed to Environment')
catch (err) {
notify("Failed ${err}")
currentBuild.result = 'FAILURE'
}
}
}
}
def notify(status)
{
****
NOTIFICATION FUCNTION
****
}
Link the Jenkinsfile in the pipeline job and provide the values- build with parameters, while building the Jenkins job.
Hope this helps.

Resources