Regarding go to specific directory and file changes

28 views
Skip to first unread message

Ashok Reddy

unread,
Apr 18, 2023, 3:01:55 AM4/18/23
to NS, jenkins...@googlegroups.com
Hi All, 

I am trying to exclude specific directory while cleaning up the workspace. 

Code: 

stage(‘’) { 
    cleanWs notFailbuild: true, 
     exclude: ‘. npn/**’

}

Error: exclude is not supported 

if I want to go to specific directory in jenkinsfile, how can we write groovy script 

nick.s...@googlemail.com

unread,
Apr 18, 2023, 5:59:56 AM4/18/23
to Ashok Reddy, NS, jenkins...@googlegroups.com
Hi Ashok

> if I want to go to specific directory in jenkinsfile, how can we write
> groovy script
Jenkins pipeline aka jenkinsfile is a plain text file and does not have directories inside - do I understand correctly that you want to refer to some folder in build area or server/agent file system? I this is what you want then the best option is definition of environment variables in your pipeline/jenkinsfile and using them in scripts/definitions. Jenkins manual (https://www.jenkins.io/doc/book/pipeline/ ) has detailed information about pipelines.

As to cleaning the workspace: unfortunately, Jenkins plugin does NOT support exclude filter. There are two options:
1. cleanWs call should have an explicit list of the folders to clean - the large number of the folders may be a proiblem
2. Second apporach requires special structuring of the Jenkins build space - the whole area defined for Jenkins build space is organised as set of folders designated for individual jobs ans set of folders that keep data persistent between jobs. For first set of the folders cleanWs can be used without necessity to filter content, for second set of folders you may have a separate housekeeping process. This approach would be my preferred option as it provides greateer flexibility. With this approach you need to have a set of the environment variables that enable the required structuring and access.


Regards,
Nick

Ashok Reddy

unread,
Apr 18, 2023, 6:27:12 AM4/18/23
to nick.s...@googlemail.com, jenkins...@googlegroups.com
Thank you for the clarification. I will share the error tomorrow regarding directory.
Reply all
Reply to author
Forward
0 new messages