Hi @anishkny,
Yes, it’s possible to do it in bulk, but you’d have to use Netlify API for that. Do note that, we don’t recommend this as there are chances your builds might break and also the API calls would be rate limited for excessive requests. But if you want to do it, you could do it like this (considering you’ve Node.js and npm installed):
Copy the following code in a file named index.js
:
const fetch = require('node-fetch')
const NetlifyAPI = require('netlify')
const AccessToken = 'Access Token Here'
const buildImage = '"xenial"' // xenial for default, focal for latest
const sitesToChange = ['netlify-subdomain1', 'netlify-subdomain2'] // leave blank to change all websites using Trusty
function manageChange(site) {
new Promise(resolve => {
fetch(`https://api.netlify.com/api/v1/sites/${site.id}`, {
method: 'PUT',
body: `{"build_image": ${buildImage}}`,
headers: {
Authorization: `Bearer ${AccessToken}`,
'Content-Type': 'application/json'
}
}).then(response => {
if (response.ok) {
return response.json()
} else {
throw response.statusText
}
}).then(() => {
console.log(`Build image for ${site.name} is now set to ${buildImage}`)
resolve(site)
}).catch(error => {
console.log(error)
})
})
}
new NetlifyAPI(AccessToken).listSites().then(sites => {
sites.forEach(site => {
if (sitesToChange.length > 0) {
if (sitesToChange.includes(site.name)) {
manageChange(site)
}
} else if (site.build_image == 'production') {
manageChange(site)
}
})
})
Run npm i netlify node-fetch
.
There are two ways you could use this:
-
Copy each website’s name in the
sitesToChange
array. If that array has even 1 website, only that would be changed. Rest would be left untouched. -
If you wish to change the build image of all websites in your account using Trusty, you should leave that array empty.
You could set your build image to xenial
or focal
by changing the buildImage
constant. Do not remove the " "
.
Finally, you need to set the AccessToken
constant. You can get its value by going here: Netlify App. Generate a new access token and use its value there. That access token would allow anyone to use API to act on your behalf. So, keep it safe or delete it once done.
Once all this is done, just run node index.js
and the script will do its job. It might not be the most optimum code, but it works.
Do let us know if you run into any errors.