diff --git a/awx/api/serializers.py b/awx/api/serializers.py index cea444243c..0314eb1fba 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -2232,6 +2232,7 @@ class InventoryUpdateSerializer(UnifiedJobSerializer, InventorySourceOptionsSeri 'source_project_update', 'custom_virtualenv', 'instance_group', + 'scm_revision', ) def get_related(self, obj): diff --git a/awx/main/migrations/0168_inventoryupdate_scm_revision.py b/awx/main/migrations/0168_inventoryupdate_scm_revision.py new file mode 100644 index 0000000000..e0fe9d28fc --- /dev/null +++ b/awx/main/migrations/0168_inventoryupdate_scm_revision.py @@ -0,0 +1,25 @@ +# Generated by Django 3.2.13 on 2022-09-08 16:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0167_project_signature_validation_credential'), + ] + + operations = [ + migrations.AddField( + model_name='inventoryupdate', + name='scm_revision', + field=models.CharField( + blank=True, + default='', + editable=False, + help_text='The SCM Revision from the Project used for this inventory update. Only applicable to inventories source from scm', + max_length=1024, + verbose_name='SCM Revision', + ), + ), + ] diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 0ecc4eb82a..4a90ad5bad 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -1191,6 +1191,14 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin, default=None, null=True, ) + scm_revision = models.CharField( + max_length=1024, + blank=True, + default='', + editable=False, + verbose_name=_('SCM Revision'), + help_text=_('The SCM Revision from the Project used for this inventory update. Only applicable to inventories source from scm'), + ) @property def is_container_group_task(self): diff --git a/awx/main/tasks/jobs.py b/awx/main/tasks/jobs.py index 35d8edf33b..33cfc30cd1 100644 --- a/awx/main/tasks/jobs.py +++ b/awx/main/tasks/jobs.py @@ -739,8 +739,7 @@ class SourceControlMixin(BaseTask): sync_task = RunProjectUpdate(job_private_data_dir=private_data_dir) sync_task.run(local_project_sync.id) local_project_sync.refresh_from_db() - if isinstance(self.instance, Job): - self.instance = self.update_model(self.instance.pk, scm_revision=local_project_sync.scm_revision) + self.instance = self.update_model(self.instance.pk, scm_revision=local_project_sync.scm_revision) except Exception: local_project_sync.refresh_from_db() if local_project_sync.status != 'canceled': @@ -759,8 +758,7 @@ class SourceControlMixin(BaseTask): else: # Case where a local sync is not needed, meaning that local tree is # up-to-date with project, job is running project current version - if isinstance(self.instance, Job): - self.instance = self.update_model(self.instance.pk, scm_revision=project.scm_revision) + self.instance = self.update_model(self.instance.pk, scm_revision=project.scm_revision) # Project update does not copy the folder, so copy here RunProjectUpdate.make_local_copy(project, private_data_dir) diff --git a/awx/ui/src/screens/Job/Job.helptext.js b/awx/ui/src/screens/Job/Job.helptext.js index d66b90b23a..8887eabe77 100644 --- a/awx/ui/src/screens/Job/Job.helptext.js +++ b/awx/ui/src/screens/Job/Job.helptext.js @@ -4,7 +4,8 @@ import { t } from '@lingui/macro'; const jobHelpText = { jobType: t`For job templates, select run to execute the playbook. Select check to only check playbook syntax, test environment setup, and report problems without executing the playbook.`, inventory: t`Select the inventory containing the hosts you want this job to manage.`, - project: t`Select the project containing the playbook you want this job to execute.`, + project: t`The project containing the playbook this job will execute.`, + project_source: t`The project from which this inventory update is sourced.`, executionEnvironment: t`The execution environment that will be used when launching this job template. The resolved execution environment can be overridden by explicitly assigning a different one to this job template.`, playbook: t`Select the playbook to be executed by this job.`, credentials: t`Select credentials for accessing the nodes this job will be ran against. You can only select one credential of each type. For machine credentials (SSH), checking "Prompt on launch" without selecting credentials will require you to select a machine credential at run time. If you select credentials and check "Prompt on launch", the selected credential(s) become the defaults that can be updated at run time.`, diff --git a/awx/ui/src/screens/Job/JobDetail/JobDetail.js b/awx/ui/src/screens/Job/JobDetail/JobDetail.js index 0202a7bcd3..b8cf41c3e7 100644 --- a/awx/ui/src/screens/Job/JobDetail/JobDetail.js +++ b/awx/ui/src/screens/Job/JobDetail/JobDetail.js @@ -146,27 +146,48 @@ function JobDetail({ job, inventorySourceLabels }) { const renderProjectDetail = () => { if ( - job.type !== 'ad_hoc_command' && - job.type !== 'inventory_update' && - job.type !== 'system_job' && - job.type !== 'workflow_job' + (job.type !== 'ad_hoc_command' && + job.type !== 'inventory_update' && + job.type !== 'system_job' && + job.type !== 'workflow_job') || + source_project ) { - return project ? ( + const projectDetailsLink = `/projects/${ + project ? project?.id : source_project?.id + }/details`; + + const jobLink = `/jobs/project/${ + project ? projectUpdate?.id : job.source_project_update + }`; + + let projectName = ''; + if (project?.name || source_project?.name) { + projectName = project ? project.name : source_project.name; + } + return project || inventory_source ? ( <> {project.name}} + label={project ? t`Project` : t`Source`} + helpText={ + project ? jobHelpText.project : jobHelpText.project_source + } + value={{projectName}} /> - + projectUpdate || job.source_project_update ? ( + + ) : null } @@ -189,9 +210,7 @@ function JobDetail({ job, inventorySourceLabels }) { value={ {job.status && } - {job.job_explanation && job.job_explanation !== job.status - ? job.job_explanation - : null} + {job?.job_explanation !== job.status ? job.job_explanation : null} } /> @@ -268,31 +287,17 @@ function JobDetail({ job, inventorySourceLabels }) { } /> - - string === job.source ? label : null - )} - isEmpty={inventorySourceLabels.length === 0} - /> - - )} - {inventory_source && inventory_source.source === 'scm' && ( - - {source_project.status && ( - + {!source_project && ( + + string === job.source ? label : null )} - - {source_project.name} - - - } - /> + isEmpty={inventorySourceLabels.length === 0} + /> + )} + )} {renderProjectDetail()} {scmBranch && (