Update Project Pipelines setting before git push

parent bc9ba39b
......@@ -138,3 +138,7 @@ To intercept git requests and learn more about the objects set up this configura
* `ERROR: Git push data files not found: 'GoError: stat /k6/tests/git/push_data/data/set_old_head-gitlabhq-8606c89683c913641243fc667edeb90600fe1a0e.bundle: no such file or directory'`
- No git push binary data files found, please ensure data was generated in [`data`](data) folder for commits that you specified for the environment.
* `Error with Project Pipelines setting update.`
- Ensure that Access Token grants the permission to update projects settings. Before git push test, Projects Pipeline setting should be disabled, otherwise git push will trigger pipelines en masse.
......@@ -110,3 +110,11 @@ export function prepareGitPushData(projects) {
});
return projects;
}
// Project Pipelines should be disabled before git push. Otherwise git push will trigger pipelines en masse.
export function updateProjectPipelinesSetting(project, state) {
let params = { headers: { "Accept": "application/json", "PRIVATE-TOKEN": `${__ENV.ACCESS_TOKEN}` } };
let formdata = { builds_access_level: state };
let res = http.put(`${__ENV.ENVIRONMENT_URL}/api/v4/rojects/${project['group']}%2F${project['name']}`, formdata, params);
/20(0|1)/.test(res.status) ? console.log(`Project Pipelines setting was ${state}`) : (logError(res), fail(`Error with Project Pipelines setting update.`));
}
......@@ -8,7 +8,7 @@ import http from "k6/http";
import { group, fail } from "k6";
import { Rate } from "k6/metrics";
import { logError, getRpsThresholds, getTtfbThreshold, getProjects, selectProject, adjustRps, adjustStageVUs } from "../../lib/gpt_k6_modules.js";
import { getRefsListGitPush, pushRefsData, checkCommitExists, prepareGitPushData } from "../../lib/gpt_git_functions.js";
import { getRefsListGitPush, pushRefsData, checkCommitExists, prepareGitPushData, updateProjectPipelinesSetting } from "../../lib/gpt_git_functions.js";
if (!__ENV.ACCESS_TOKEN) fail('ACCESS_TOKEN has not been set. Skipping...')
......@@ -24,7 +24,8 @@ export let options = {
"http_reqs": [`count>=${rpsThresholds['count']}`]
},
rps: gitProtoRps,
stages: gitProtoStages
stages: gitProtoStages,
teardownTimeout: '30s'
};
export let authEnvUrl = __ENV.ENVIRONMENT_URL.replace(/(^https?:\/\/)(.*)/, `$1test:${__ENV.ACCESS_TOKEN}@$2`)
......@@ -39,9 +40,11 @@ export function setup() {
console.log(`Success Rate Threshold: ${parseFloat(__ENV.SUCCESS_RATE_THRESHOLD) * 100}%`)
// Test should only run if specified commits exist in the project
// and if Project Pipelines are disabled. Otherwise git push will trigger pipelines en masse.
projects.forEach(project => {
checkCommitExists(project, project['git_push_data']['branch_current_head_sha']);
checkCommitExists(project, project['git_push_data']['branch_new_head_sha']);
updateProjectPipelinesSetting(project, "disabled");
});
}
......@@ -69,8 +72,8 @@ export default function () {
}
export function teardown() {
// Ensure that all branches were restored to the original `branch_current_head_sha`
projects.forEach(project => {
// Ensure that all branches were restored to the original `branch_current_head_sha`
let params = {
headers: {
"Accept": "application/x-git-receive-pack-result",
......@@ -78,5 +81,7 @@ export function teardown() {
}
};
http.post(`${authEnvUrl}/${project['group']}/${project['name']}.git/git-receive-pack`, project.data.branch_set_old_head, params);
// Enable Pipelines in the Project af the test
updateProjectPipelinesSetting(project, "enabled");
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment