Note: The bulk-publish-entries-assets command-line utility will soon be deprecated. We recommend you to check out our latest CLI documentation for performing content management activities.
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. Read More.
Contentstack publishing script lets you auto publish your entries and assets depending upon the cases given below
- Publish the unpublished/draft entries
- Publish the assets of a stack
- Publish the entries of a stack
- Unpublish entries/assets of a stack
- Publish edits made on entries on particular environment
- Publish entries/assets from one environment to other
- Publish Localized entries when nonlocalized field of master Entry is updated
- Update and publish entries when a new field is added to content type
- Revert published entries through script from logs
NOTE: Publishing process will fail if Required/Mandatory fields are empty
This Script uses Bulk Publish api to publish the contents, However if the bulk Operation is not enabled for your organization, set the bulkPublish/Unpublish flag in config to false.We recommend using Bulk publish to avoid slow/less failed publishing due to single entry/asset publish api.
Before we dive into the use cases, let's ensure that we install the required dependencies and make changes in the configuration files which will remain common for all uses cases that we have discussed
$ npm install
module.exports = {
apikey:'', //api key of the stack
apiEndPoint:'https://api.contentstack.io',
cdnEndPoint:'https://cdn.contentstack.io',
manageToken:'',//management token for the stack
}
Specify case details in config file
module.exports = {
publish_unpublished_env:{
contentTypes:['test'], //list of contentTypes
sourceEnv : 'staging', //sourceEnv
environments:['testdin1996'],
locales:['en-us'],
bulkPublish: true, //keep this flag as false if bulkPublish feature is not present in your plan
}
}
Start publishing
$ npm run publish_unpublish
Specify case details in config file
module.exports = {
publish_assets:{
environments:['bulktest'],
folderUid:"cs_root", //Id of the folder to be published, cs_root for assets
bulkPublish: true,
}
}
Start publishing
$ npm run publish_assets
Specify case details in config file
module.exports = {
publish_entries:{
contentTypes:['redirect_rule'], //list of contentTypes which needs to be published
locales:['en-us'], //list of locales which need to be considered for mentioned CTs
environments:['bulktest'], // destination publish environments
publishAllContentTypes : false, //if you want to publish entire contentTypes
bulkPublish:true
}
}
Start publishing
$ npm run publish_entries
Specify case details in config file
module.exports = {
Unpublish :{
filter:{
environment: 'bulktest', //source environment
content_type_uid: '', //Add content type uid to be unpublished. Keep this blank to consider all
locale: 'en-us', //locale filters
type:'entry_published,asset_published' //entries and assets both will be unpublished, remove asset_published if u want to unpublish only entries and vice versa.
},
deliveryToken:'' //deliveryToken of the source environment,
bulkUnpublish: true,
}
}
Start publishing
$ npm run unpublish
Specify case details in config file
module.exports = {
publish_edits_on_env: {
contentTypes: ['test','helloworld'],
sourceEnv: 'test',
environments: ['test'],
locales: ['en-us',],
bulkPublish: true,
},
}
Start publishing
$ npm run publish_edits
Specify case details in config file
module.exports = {
cross_env_publish:{
filter: {
environment: 'bulktest', // source environment
content_type_uid: '', // //Add content type uid to be published. Keep this blank to consider all (keep this empty while publishing only assets)
locale: 'en-us', // locale filters. Keep this blank to consider all
type: 'asset_published,entry_published', //entries and assets both will be published, remove asset_published if u want to publish only entries and vice versa.
},
deliveryToken: '', // deliveryToken of the source environment
destEnv:[''], //environments where it needs to be published
bulkPublish: true,
}
}
Start publishing
$ npm run cross_publish
Specify case details in config file
module.exports = {
nonlocalized_field_changes: {
sourceEnv: 'production', //source Environment
contentTypes: ['testdin'],
environments: ['production'], //publishing Environments
bulkPublish: true,
},
}
Start publishing
$ npm run publish_localized
Specify case details in config file
module.exports = {
addFields: {
deleteFields: ['updated_by', 'created_by', 'created_at', 'updated_at', '_version', 'ACL'],
locales: ['en-us'],
contentTypes: ['helloworld'], // list to contentType entries to be updated
environments: ['test'], // list of environments where it needs to be published
defaults: {
number: null,
boolean: false,
isodate: [],
file: null,
reference: [],
},
},
bulkPublish: true,
}
Start publishing
$ npm run add_fields
Start publishing
$ npm run revert ${logFilename}
logFilename is success logs of particular execution
For example npm run revert 1587270350288.bulkPublishEntries.success
Entries which failed to publish are stored in logs directory with unique name ending with .error. In order to retry entries of those log file, you need execute same script with retryFailed flag along with ${logFilename} which follows after it
$ npm run publish_entries -- -retryFailed ${logFilename}
$ npm run publish_assets -- -retryFailed ${logFilename}
for example //npm run publish_entries -- -retryFailed 18003bulkPublishEntries.error
- For less publish failure of entries we recommend you to try one content type at a time
- Does not work on custom fields
- Does not work on mandatory fields
- To publish to a specific version we are using single entry/asset publish api instead of bulkpublish