# How to use changeset in scripted syntax

**URL:** <https://community.jenkins.io/t/how-to-use-changeset-in-scripted-syntax/22089>\
**Category:** Ask a question\
**Tags:** question, pipeline\
**Created:** [October 18, 2024, 12:39pm UTC](https://community.jenkins.io/t/how-to-use-changeset-in-scripted-syntax/22089 "2024-10-18T12:39:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ntnhut](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/ntnhut/32/10968_2.png) [@ntnhut](https://community.jenkins.io/u/ntnhut)\
**Post date:** [October 18, 2024, 12:39pm UTC](https://community.jenkins.io/t/how-to-use-changeset-in-scripted-syntax/22089/1 "2024-10-18T12:39:37Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [October 21, 2024, 5:21pm UTC](https://community.jenkins.io/t/how-to-use-changeset-in-scripted-syntax/22089/2 "2024-10-21T17:21:21Z")

</div>

Hello and welcome to this community, @ntnhut. 👋

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 🤞 example of how you could maybe do this:

```auto
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. 🤷
