I use the /v1/jobs endpoint to submit my job, and for that I need to convert my job.hcl to job.json first and then submit, But I would like to use the job.hcl directly and show it in the UI as default as it is much compact and easier to work with. Is there a way this can be achieved? I searched web and this forum and could only find /v1/jobs/parse endpoint but, will this preserve the HCL?
Submission(JobSubmission: <optional>) - Specifies the original HCL/HCL2/JSON definition of the job. This data is useful for reference only, it is not considered for the actual scheduling of Job.
Hi @ayushk , thanks for raising the question, and thanks @Kamilcuk for responding. Apologies for not having this better-documented. JobSubmission data should include at a minimum a Format string ("hcl2") and the Source as a stringified representation of your jobspec hcl. Here is an example using our hello-world job template:
{
"Job": {
"Affinities": null,
"AllAtOnce": false,
...
"VaultToken": "",
"Version": 0,
"meta": {}
},
"Submission": {
"Source": "job \"hello-world\" {\n # Specifies the datacenter where this job should be run\n # This can be omitted and it will default to [\"*\"]\n datacenters = [\"*\"]\n\n meta {\n # User-defined key/value pairs that can be used in your jobs.\n # You can also use this meta block within Group and Task levels.\n foo = \"bar\"\n }\n\n # A group defines a series of tasks that should be co-located\n # on the same client (host). All tasks within a group will be\n # placed on the same host.\n group \"servers\" {\n\n # Specifies the number of instances of this group that should be running.\n # Use this to scale or parallelize your job.\n # This can be omitted and it will default to 1.\n count = 1\n\n network {\n port \"www\" {\n to = 8001\n }\n }\n\n service {\n provider = \"nomad\"\n port = \"www\"\n }\n\n # Tasks are individual units of work that are run by Nomad.\n task \"web\" {\n # This particular task starts a simple web server within a Docker container\n driver = \"docker\"\n\n config {\n image = \"busybox:1\"\n command = \"httpd\"\n args = [\"-v\", \"-f\", \"-p\", \"${NOMAD_PORT_www}\", \"-h\", \"/local\"]\n ports = [\"www\"]\n }\n\n template {\n data = <<-EOF\n <h1>Hello, Nomad!</h1>\n <ul>\n <li>Task: {{env \"NOMAD_TASK_NAME\"}}</li>\n <li>Group: {{env \"NOMAD_GROUP_NAME\"}}</li>\n <li>Job: {{env \"NOMAD_JOB_NAME\"}}</li>\n <li>Metadata value for foo: {{env \"NOMAD_META_foo\"}}</li>\n <li>Currently running on port: {{env \"NOMAD_PORT_www\"}}</li>\n </ul>\n EOF\n destination = \"local/index.html\"\n }\n\n # Specify the maximum resources required to run the task\n resources {\n cpu = 50\n memory = 64\n }\n }\n }\n}",
"Format": "hcl2"
}
}
See the struct that Kamilcuk linked above for optional variables as well.