How to use changeset in scripted syntax

I tried to use changeset in a scripted pipeline like the following, but it does not work as expected. It would be great if there is a way to achieve it in a
scripted syntax, as I do not want to change our Jenkinsfile to a declarative one.

node {
	stage('Fetch Repository') {
		checkout scm
	}
    stage('check file') {
		if (!changeset("file.json")) {
			unstable("file.json unchanged!")
		}
	}
    ...
}

Hello and welcome to this community, @ntnhut. :wave:

I’m not so sure it’s the best way to do it, but I think you could achieve the desired functionality by using the git command to check for changes in a specific file.

Here is an untested :crossed_fingers: example of how you could maybe do this:

node {
    stage('Fetch Repository') {
        checkout scm
    }
    stage('Check File') {
        def changes = sh(script: 'git diff --name-only HEAD~1 HEAD', returnStdout: true).trim()
        if (!changes.contains('file.json')) {
            unstable("file.json unchanged!")
        }
    }
    // Other stages...
}

The checkout scm command fetches the repository.
The sh step runs a git diff command to get the list of changed files between the last two commits.
The script checks if file.json is in the list of changed files. If not, it marks the build as unstable. :person_shrugging: